Reputation: 792
I am trying to create a word puzzle, but I got a NameError after I prompt the player to enter a guess.
My code:
.
.
.
print("The word is something like " + guess)
player_guess_letter= input("Guess a letter:")
After I enter a guess, say "f" in the error "NameError: name 'f' is not defined".
Upvotes: 1
Views: 36
Reputation: 69923
The problem is that you are using Python 2, so instead of input
use raw_input
as follows:
player_guess_letter= raw_input("Guess a letter:")
In Python 2, input()
is equivalent to eval(raw_input())
. Thus, it is trying to eval the value you entered. See more in the docs.
In Python 3, you won't have this issue.
Upvotes: 1