View Single Post
Old Jan 24th, 2008, 12:00 PM   #36
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

About the character encoding, you were writing the file in Microsoft Word or WordPad or some other word-processing application now weren't you... Source code should always be in plaintext. So use the Python GUI. Word processing applications always bloat your file with other information pertaining to the font, size, formatting, etc... Plaintext means there are ASCII characters, and nothing more, which is why you should be using IDLE (or Notepad) to write your Python scripts.



Now... "raw_input" is for taking in strings. "input" is for taking in numbers.

If you try to compare a string with the value obtained from randint (a number), it doesn't work as expected.

>>> print "50" > 40
True
>>> print "50" > 60
True

You want to compare numbers with numbers.

>>> print 50 > 40
True
>>> print 50 > 60
False

You can obtain a number from the user with "input" rather than "raw_input".

Or you can typecast the string to an integer with guess = int(raw_input("Enter A Number: ")) which is "safer".

I forgot I had made that change to your code on my version when I was fixing all of the syntax errors.
Sane is offline   Reply With Quote