Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 23rd, 2008, 6:20 PM   #31
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: My pyguessinggame

That's so strange. That error message means there's some non-ascii characters in your source code. I can't see any...

Try removing that first line all together.
Sane is offline   Reply With Quote
Old Jan 23rd, 2008, 6:42 PM   #32
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: My pyguessinggame

same thing everytime
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Jan 23rd, 2008, 6:45 PM   #33
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: My pyguessinggame

with just a raw_imput command it still has the same message, could it be the path, mine is
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C;\Python25
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Jan 23rd, 2008, 8:09 PM   #34
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: My pyguessinggame

lol, you're still saying "raw_imput" instead of "raw_input".

It doesn't sound like a problem with your Path if Python is successfully running. It sounds like a problem with how the files are being encoded, because it thinks you're trying to use illegal characters.

Have you tried running the program in IDLE? Open up IDLE (Python GUI). Open your script. Hit F5.
Sane is offline   Reply With Quote
Old Jan 24th, 2008, 11:29 AM   #35
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: My pyguessinggame

but I am not using illegal characters, I am using a typical American keyboard, you will find no chinese characters on this keyboard, wait could it be the font? (I am truly sorry about the raw_imp- whoops I mean raw_input mistake for some reason I just am having trouble spelling it right)

PS. I got the game to run, well sorta, it went like this

1.) I copy guessgamev2.0.py into the python command line, via. copy + pasting the text

2.) I type in start()

3.) Here is the result (stuff in blue is input)
I am thinking of a number that is in between 1 and 100 3  that guess is way too high, the answer has to be 100 or lower 1000 that guess is way too high, the answer has to be 100 or lower -1000000 that guess is way too high, the answer has to be 100 or lower 0 that guess is way too high, the answer has to be 100 or lower, ect. ect. ect. ect.

As you can see, nothing happened that was supposed to happen.
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Jan 24th, 2008, 12:00 PM   #36
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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
Old Jan 24th, 2008, 1:24 PM   #37
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: My pyguessinggame

yeah I got it to work with just double clicking, sorta

One last time
#guessgame********** (1/20/08)
from random import randint
def start():
   answer=randint(1,101) #the answer
   guessnum=0 #number of user guesses
   guess=input('''I am thinking of a number that is in between 1 and 100''')#the current guess of the user
   while guess != answer:
      guessnum=guessnum+1
      if guess > 100:
         print '''that guess is way too high, the answer has to be 100 or lower''' 
         guess=input ('''guess again please, within the limit this time''')
      elif guess == 0:
         print 'actually zero is not within the 1-100 range'
         guess=input('guess again please')
      elif guess < 0:
         print 'are you testing me?'
         guess=input('guess again, in the positives please')
      elif guess > 0 and guess < 100 and guess < answer:
         print 'that guess is below the answer'
         guess=input('try guessing again')
      elif guess >0 and guess < 100 and guess > answer:
         print 'guess lower, your answer is to high'
         guess=input('try once more')
   if guess == answer:
      print 'congratualtions, that took', guessnum, 'tries'
   if __name__ == '__main__':
      start()
      print
      raw_input('press return')
   else:
      print 'Module guessgame imported'
      print 'to run, type:guessgame.start()'
      print 'to refresh, type:reload (guessgame)'
#end game

raw_input('press enter to quit')

Came out with

Only the ending ended up getting printed

EDIT:Whooooooop!!!! I did it, except I did it only by coping the data to the command line. I need to figure out how to remotely open the file.
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.

Last edited by Chuckiferd; Jan 24th, 2008 at 1:35 PM.
Chuckiferd is offline   Reply With Quote
Old Jan 24th, 2008, 2:07 PM   #38
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: My pyguessinggame

You still have code indented incorrectly...

   if __name__ == '__main__':
      start()
      print
      raw_input('press return')
   else:
      print 'Module guessgame imported'
      print 'to run, type:guessgame.start()'
      print 'to refresh, type:reload (guessgame)'

Should be indented like so:

#guessgame********** (1/20/08)
from random import randint
def start():
   answer=randint(1,101) #the answer
   guessnum=0 #number of user guesses
   guess=input('''I am thinking of a number that is in between 1 and 100''')#the current guess of the user
   while guess != answer:
      guessnum=guessnum+1
      if guess > 100:
         print '''that guess is way too high, the answer has to be 100 or lower''' 
         guess=input ('''guess again please, within the limit this time''')
      elif guess == 0:
         print 'actually zero is not within the 1-100 range'
         guess=input('guess again please')
      elif guess < 0:
         print 'are you testing me?'
         guess=input('guess again, in the positives please')
      elif guess > 0 and guess < 100 and guess < answer:
         print 'that guess is below the answer'
         guess=input('try guessing again')
      elif guess >0 and guess < 100 and guess > answer:
         print 'guess lower, your answer is to high'
         guess=input('try once more')
   if guess == answer:
      print 'congratualtions, that took', guessnum, 'tries'
if __name__ == '__main__':
   start()
   print
   raw_input('press return')
else:
   print 'Module guessgame imported'
   print 'to run, type:guessgame.start()'
   print 'to refresh, type:reload (guessgame)'
#end game

raw_input('press enter to quit')

And what in the world are you talking about with "remotely opening the file"?

Again... just use IDLE and run it from there. As simple as that...
Sane is offline   Reply With Quote
Old Jan 24th, 2008, 3:00 PM   #39
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Re: My pyguessinggame

By 'remotely activating the file' I meant opening it and running it without having to copy and paste from a notepad document.
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't.
Chuckiferd is offline   Reply With Quote
Old Jan 24th, 2008, 3:14 PM   #40
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: My pyguessinggame

Yes, for the fourth time. IDLE!
Start -> Programs -> Python -> IDLE (Python GUI)
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:09 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC