[Tutor] unknown error in simple program
Ewald Ertl
ewald.ertl at hartter.com
Tue Feb 14 08:28:25 CET 2006
Hi Eli!
You have a lot of calls to input() in your code.
When requesting help on input you get the following output:
>>> help(input)
Help on built-in function input:
input(...)
input([prompt]) -> value
Equivalent to eval(raw_input(prompt)).
As you can see, the data you input is put as argument to eval, which tries to
interpret the input as Python-source code.
What you intended is a raw_input(). This reads the data from
standard input and returns it to you.
HTH Ewald
Eli Zabielski wrote:
> I am reading "Python Programming for the absolute beginner" and am on
> chapter 4 challenges.
> It says to create a program to let the player guess letters of the word
> (I haven't tried to incorporate a guess limit yet like it says)
> my program looks fine to me, but I get a fat juicy error when I run it
>
> My program:
>
> # Guess My Word
> # Players pick letters in a random secret word
> # Eli Zabielski-2/13/06
> import random
> print "Hello, I will give you 5 chances to guess letters of one of my
> secret words.\n On the final chance, you must guess the word"
> WORDS = ("python", "jumble", "difficult", "answer", "xylophone",
> "recon", "recordable")
> word=random.choice(WORDS)
> print "The word is", len(word), "letters long."
> guess=input("guess one letter")
> tried_good=()
> tried_bad=()
> guess_count=0
> while guess not in word:
> guess_count+=1
> guess+=tried_bad
> print "Nope, try again\n"
> print "Bad tries",tried_bad
> guess=input("\nguess one letter")
> if guess_count==4:
> "You have to guess the word now"
> guess_word=input("What say you")
> guess_word=guess_word.lower()
> while guess in word:
> print "Good, you got one"
> guess+=tried_good
> print "Bad tries",tried_bad
> print "Good tries", tried_good
> guess=input("\nguess one letter")
> if guess_count==4:
> "You have to guess the word now"
> guess_word=input("What say you")
> guess_word=guess_word.lower()
> if guess_word==word:
> print "Good, you got it!"
> elif guess_word != word:
> print "Aww, thats too bad, the word is mine forever"
> exit=input("Press enter to exit.")
>
>
>
> And I get: (No matter what letter I guess)
>
> Traceback (most recent call last):
> File
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
> exec codeObject in __main__.__dict__
> File "C:\Documents and
> Settings\Eli\Desktop\Games\Applications\Programs\Guess the word\Guess
> the word 1.0.py <http://1.0.py>", line 10, in ?
> guess=input("guess one letter")
> File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\app.py",
> line 372, in Win32Input
> return eval(raw_input(prompt))
> File "<string>", line 0, in ?
> NameError: name 'e' is not defined
>>>>
>
> I have been attempting to find the problem for 2 hours now and try to
> solve it on my own, but I can't do it this time.
>
> Thanks for the help
>
> --
> Eli Zabielski
>
>
More information about the Tutor
mailing list