View Single Post
Old Jan 20th, 2008, 1:59 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: My pyguessinggame

I really don't understand how your code could possibly have so many syntax mistakes, yet be code that you've written at the same time. Were you writing this out by hand or something??

Some of the most notable mistakes:
  • It's __name__. Not _neame_.
  • It's '__main__'. Not '_main_'.
  • It's start(). Not start():.
  • It's raw_input. Not raw_imput.
  • It's from random import *. Not #import whrandom.

Finally, all of your indentation is completely and utterly wrong.

I'm tired of being someone's IDE. These are syntax mistakes. If you're making this many mistakes, then you don't yet understand how to work with Python. You need to learn to follow tutorials carefully, experiment for yourself, and you need to learn how to read the errors shown by the Python Traceback.

Fixing all of these mistakes makes the code executable. But it still does not work as required, because the logic of the script is incorrect. I'm not fixing that part for you.

from random import *
def start():
    answer=randint(1,101) #the answer
    guessnum=0 #number of user guesses
    guess=raw_input ('guess my number, it is between 1 and 100') #user's guess
    while guess!= answer:
        guessnum=guessnum+1
        if(guess <= 0):
           print '''My number is between 1-100, you gave a negative just to see what I would say.'''
        elif (guess >= 101):
           print'no the answer is below 101'
        elif (guess > answer):
           print 'Too high'
        elif (guess<answer):
           print 'guess higher, your guess is too low'
        else:
           print 'Right on, congratualations that took', guessnum, 'tries.'

#I truly don't understand from here to.............
if __name__ == '__main__':
   start()
   print
   raw_input('press return')
else:
   print 'Module guessgame imported'
   print 'to run, type:guessgame.start()'
   print 'to refreash, type:reload (guessgame)'
#.....here
#end
Sane is offline   Reply With Quote