Jump to content
  • Advertisement

koka282

Member
  • Content Count

    89
  • Joined

  • Last visited

Everything posted by koka282

  1. I need to one give me the string between ~ and ^. I have a string like this: ~~~~ ABC ^ DEF ^ HGK > LMN ^ I need to get the string between them with python. I've tried this: import re target = ' ~~~~ ABC ^ DEF ^ HGK > LMN ^ ' matchObj = re.findall(r'~(.*?)\^', target) print matchObj But the result is:['~~~ ABC '] What I expect is: [ABC , DEF , HGK , LMN ] or [^ABC , ^DEF , ^HGK , LMN ] I want to do all this because i am trying to extract text from an html page. like this example <td class="cell-1"> <div><span class="value-frame">&nbsp;~~~~ ABC ^ DEF ^ HGK > LMN ^ </span></div> </td>  
  2. hi,  i have a custom module, I want to put it in the directory to import it. What should I do?   i got this error : importError: No module named 'pyperclip'      ?i use Linux Debian   i downloaded the module from :   https://pypi.python.org/pypi/pyperclip/     what should i do to import it     i tried many commands in Konsole   like sudo apt-get install python3-setuptools etc....             Thanks
  3. koka282

    error while importing module

    i searched before and i saw some typed this for 64 bit then i got this error !  :) Thanks :)
  4. hi all i have little problem here import pyHook , pythoncom ,sys , logging Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import pyHook , pythoncom ,sys , logging File "C:\Python27\lib\site-packages\pythoncom.py", line 2, in <module> import pywintypes File "C:\Python27\lib\site-packages\win32\lib\pywintypes.py", line 124, in <module> __import_pywin32_system_module__("pywintypes", globals()) File "C:\Python27\lib\site-packages\win32\lib\pywintypes.py", line 64, in __import_pywin32_system_module__ import _win32sysloader ImportError: DLL load failed: %1 is not a valid Win32 application. Thanks :)
  5. Line 3 & 4  were visible for 1 sec then it invisible ! :D   But No problem ! :)   i think Sublime not bad i will use it    Thanks
  6. hi all, i'm using sublime text 2  and when i run my code on it  class hangman(): def __init__(self): print "Welcome to Hangman game " print "if you want to play type 1 if you don't want type 2" user_choice = raw_input("> ") if user_choice == "1": print "Nice" self.startgame() elif user_choice == "2": print "Bye" exit() else: print "i can't understand please choose again" def hangman_graphic(self, guesses): if guesses == 0: print "________ " print "| | " print "| " print "| " print "| " print "| " elif guesses == 1: print "________ " print "| | " print "| 0 " print "| " print "| " print "| " elif guesses == 2: print "________ " print "| | " print "| 0 " print "| / " print "| " print "| " elif guesses == 3: print "________ " print "| | " print "| 0 " print "| /| " print "| " print "| " elif guesses == 4: print "________ " print "| | " print "| 0 " print "| /|\ " print "| " print "| " elif guesses == 5: print "________ " print "| | " print "| 0 " print "| /|\ " print "| / " print "| " else: print "________ " print "| | " print "| 0 " print "| /|\ " print "| / \ " print "| " print "The noose tightens around your neck, and you feel the" print "sudden urge to urinate." print "GAME OVER!" self.__init__() game = hangman() I get error : Welcome to Hangman game Traceback (most recent call last):   File "C:\Python27\hangg.py", line 69, in <module>   if you want to play type 1 if u don't want type 2 >     [Finished in 0.1s with exit code 1]game = hangman()   File "C:\Python27\hangg.py", line 5, in __init__     user_choice = raw_input("> ") EOFError: EOF when reading a line     But when i use python IDLE i don't get error !?   Thanks
  7. it works when i use sublimerepl but it didn't print line 3 and 4  and i should everytime to run my script Tools>sublimerepl>python !???
  8. i know it will crash i just was trying it on IDLE and Sumblim i get error on sublime only    i download it then i put it in Pristine Packages and doesn't work
  9. koka282

    Hangman error

    hi all, i was reading someone's code i want to make like this project but when i run it i get error !! can you tell me what should i do ?! class Hangman(): def __init__(self): print "Welcome to 'Hangman', are you ready to die?" print "(1)Yes, for I am already dead.\n(2)No, get me outta here!" user_choice_1 = raw_input("->") if user_choice_1 == '1': print "Loading nooses, murderers, rapists, thiefs, lunatics..." self.start_game() elif user_choice_1 == '2': print "Bye bye now..." exit() else: print "I'm sorry, I'm hard of hearing, could you repeat that?" self.__init__() def start_game(self): print "A crowd begins to gather, they can't wait to see some real" print "justice. There's just one thing, you aren't a real criminal." print "No, no. You're the wrong time, wrong place type. You may think" print "you're dead, but it's not like that at all. Yes, yes. You've" print "got a chance to live. All you've gotta do is guess the right" print "words and you can live to see another day. But don't get so" print "happy yet. If you make 6 wrong guess, YOU'RE TOAST! VAMANOS!" self.core_game() def core_game(self): guesses = 0 letters_used = "" the_word = "pizza" progress = ["?", "?", "?", "?", "?"] while guesses < 6: guess = raw_input("Guess a letter ->") if guess in the_word and not in letters_used: print "As it turns out, your guess was RIGHT!" letters_used += "," + guess self.hangman_graphic(guesses) print "Progress: " + self.progress_updater(guess, the_word, progress) print "Letter used: " + letters_used elif guess not in the_word and not in letters_used: guesses += 1 print "Things aren't looking so good, that guess was WRONG!" print "Oh man, that crowd is getting happy, I thought you" print "wanted to make them mad?" letters_used += "," + guess self.hangman_graphic(guesses) print "Progress: " + "".join(progress) print "Letter used: " + letters_used else: print "That's the wrong letter, you wanna be out here all day?" print "Try again!" def hangman_graphic(self, guesses): if guesses == 0: print "________ " print "| | " print "| " print "| " print "| " print "| " elif guesses == 1: print "________ " print "| | " print "| 0 " print "| " print "| " print "| " elif guesses == 2: print "________ " print "| | " print "| 0 " print "| / " print "| " print "| " elif guesses == 3: print "________ " print "| | " print "| 0 " print "| /| " print "| " print "| " elif guesses == 4: print "________ " print "| | " print "| 0 " print "| /|\ " print "| " print "| " elif guesses == 5: print "________ " print "| | " print "| 0 " print "| /|\ " print "| / " print "| " else: print "________ " print "| | " print "| 0 " print "| /|\ " print "| / \ " print "| " print "The noose tightens around your neck, and you feel the" print "sudden urge to urinate." print "GAME OVER!" self.__init__() def progress_updater(self, guess, the_word, progress): i = 0 while i < len(the_word): if guess == the_word[i]: progress[i] = guess i += 1 else: i += 1 return "".join(progress) game = Hangman()   Thanks all
  10. Hi, i have little problem here    i was trying to make rock,paper,scissor project  while running it    i got this error UnboundLocalError: local variable 'comp' referenced before assignment   what should i do to fix it ?   code: from random import randint #Computer draws hand. def comp(): r=randint(1,3) if r == 1: hand = "rock" if r == 2 : hand = "paper" if r == 3 : hand = "scissor" return hand # who is the winner. def whowin(you,comp): if you == comp: winner = "tie" elif comp == ("rock" and you == "scissor") or comp == ("scissor" and you == "paper") or comp == ("paper" and you == "rock"): winner = "comp" else: winner = "you" return winner # start def play(): print "------welcome to my game------" comp_wins = 0 you_wins = 0 tie_wins = 0 while True: you = raw_input("Please choose rock or scissor or paper ") you=you.lower() comp = comp() winner = whowin(you,comp) if not you == "rock" or you == "paper" or you =="scissor": print" invalid" continue play() Thanks
  11.   Yes         i must focus more i often type them by mistake          it should be  elif (comp == "rock" and you == "scissor") or (comp == "scissor" and you == "paper") or (comp == "paper" and you == "rock")             i want to make the comp be variable in whowin function  & comp will be the hand value like : paper or rock ,,  i should type pc=comp() & whowin(you,pc)     you mean like that ?       Thanks     Smile
  12. You use the phrase is-a when you talk about objects and classes being related to each other by a class relationship. You use has-a when you talk about objects and classes that are related only because they reference each other.     Can you give me an example shows the meaning ??   i can't understand what does he mean with ! related to each other by a class relationship & because they reference each other.       &  def __init__(self, name):       self.name = name why we must type this line ?? (self.name = name)   Thanks all
  13. sorry for hard understanding  i shouldn't ask sorry
  14.  must be defined in a scope containing the derived class definition       but see : class product(object): why we type object !!  where i type object !   Sorry for hard understanding     .................   but i think  in class Teacher(Human) def __init__(self,name) self.name=name it was inheritance   but in .. class product(object): i here type the object Because (it is not an inheritance from another class)   Thanks
  15. Ty but please answer this question class Teacher(Human) def __init__(self,name) self.name=name now we are talking about the object that object have name etc so you are talking about the human not the teacher ,, between the bracket i type the object right ?? so now saying human has-a name not teacher right ?
  16. Hi, i'm learning from http://learnpythonthehardway.org/book/ex39.html def new(num_buckets=256): """Initializes a Map with the given number of buckets.""" aMap = [] for i in range(0, num_buckets): aMap.append([]) return aMap def hash_key(aMap, key): """Given a key this will create a number and then convert it to an index for the aMap's buckets.""" return hash(key) % len(aMap) def get_bucket(aMap, key): """Given a key, find the bucket where it would go.""" bucket_id = hash_key(aMap, key) return aMap[bucket_id] def get_slot(aMap, key, default=None): """ Returns the index, key, and value of a slot found in a bucket. Returns -1, key, and default (None if not set) when not found. """ bucket = get_bucket(aMap, key) for i, kv in enumerate(bucket): k, v = kv if key == k: return i, k, v return -1, key, default def get(aMap, key, default=None): """Gets the value in a bucket for the given key, or the default.""" i, k, v = get_slot(aMap, key, default=default) return v def set(aMap, key, value): """Sets the key to the value, replacing any existing value.""" bucket = get_bucket(aMap, key) i, k, v = get_slot(aMap, key) if i >= 0: # the key exists, replace it bucket[i] = (key, value) else: # the key does not, append to create it bucket.append((key, value)) def delete(aMap, key): """Deletes the given key from the Map.""" bucket = get_bucket(aMap, key) for i in xrange(len(bucket)): k, v = bucket[i] if key == k: del bucket[i] break def list(aMap): """Prints out what's in the Map.""" for bucket in aMap: if bucket: for k, v in bucket: print k, v i searched for hash function, hash table,hashmap return hash(key) % len(aMap)  How does it work? & what he mean with the bucket when i read about hash  i think i couldn't  understand what he mean with bucket  (Given a key this will create a number and then convert it to an index for the aMap's buckets) but i want to know how does it work  i run it and tried many times I understood things, and things I did not understand     & if u don't understand what i mean please tell me  & sry for asking  i will try again ....     Thanks
  17. hi, i was reading this code  Can you try to Run this code first  & if it works in right way(Working properly) please explain to me it !!!  from sys import exit def gold_room(): print "This room is full of gold. How much do you take?" choice = raw_input("> ") #ask the user ! if "0" in choice or "1" in choice: how_much = int(choice) else: dead("Man, learn to type a number.") if how_much < 50: print "Nice, you're not greedy, you win!" exit(0) else: dead("You greedy bastard!") def dead(why): print why, "Good job!" exit(0) gold_room() Thanks
  18. koka282

    Can you explain to me this code !

    please no down votes and understand me :) when you type 100 it will check  if the number has 1 or 0 so the condition is true so how_much = int(choice) so i shouldn't get "You greedy bastard!"   Thanks :)
  19. I'm 15 Years Old  Do I begin learning python late? i want to learn python & web languages & Networking i challenge one  he said I do not know anything Laugh & was making fun of me because i don't know in programming like him maybe i shouldn't write that here sorry but i want to talk  i will learn i want to be professional  
  20. koka282

    Can you explain to me this code !

    Lysy i read the code!! ok i need answer for this question to be sure ! Try to type 100 you will get  You greedy bastard! Good job! that's mean  else: dead("You greedy bastard!") & i should get that  if "0" in choice or "1" in choice: how_much = int(choice)   Sorry for hard understanding Thanks
  21. koka282

    Can you explain to me this code !

    if "0" in choice or "1" in choice: how_much = int(choice) else: dead("Man, learn to type a number.") the first line in that part checks if the text you've entered contains "0" or "1" , if it does it will try to convert the text to a number and assign it to the how_much variable , it the text doesn't contain 0 or 1 it will run the dead function with "Man, learn to type a number." as its parameter. "55" doesn't contain 0 or 1 so it will run the dead function which prints the parameter "Man, learn to type a number." followed by "Good job!" and then it exits.   I know that but  else: dead("You greedy bastard!")   55 isn't less than 50 so why we don't get dead("You greedy bastard!")   how it works ?   sorry for hard understanding    Thanks all
  22. koka282

    Can you explain to me this code !

    it will run & i know it is simple but why when i type 55 the result: Man, learn to type a number. Good job! (why i get this result ) why i the result not  dead("You greedy bastard!") Sorry Lysy but when i type the numbers i get many questions
  23. koka282

    Did I begin learning late?

    why down votes ?!
  24. koka282

    Did I begin learning late?

      Nice   & Thanks all :) I'm learning now  Never Give up ! & i will be better than who make fun of me but for myself because i love programming :)
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!