[Tutor] unknown error in simple program
Eli Zabielski
eli.usmc.recon at gmail.com
Tue Feb 14 07:00:10 CET 2006
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", 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060213/027eebef/attachment.html
-------------- next part --------------
# 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.")
More information about the Tutor
mailing list