'When I run the code, I get an error the guesses is not defined [closed]
I made this quiz game. It runs fine, and you can answer, but when you press answer, it gives me an error. I've tried switching variables, but I don't know where it started. Here's my code.
def new_game():
geusses = []
correct_geusses = 0
question_num = 1
for key in questions:
print(key)
for i in options [question_num-1]:
print(i)
guess = input("Enter(A, B, C, or D)")
guess = guess.upper()
guesses.append(guesses)
correct_geusses += check_answer(questions.get(key),guess)
question_num += 1
#-----------------------
def check_answer(answer, guess):
if answer == guesses:
print("Nice Job!")
return 1
else:
print("Wrong!")
#-----------------------
def display_score():
pass
#-----------------------
def play_again():
pass
#-----------------------
questions = {
"Who was the first US president? : " : "A"
}
#----------------------------
options = [["A. George Washington," "B. Ben Franklin," "C. Elon Musk," "D. None of the above" ]]
#-----------------------------------
new_game()
Solution 1:[1]
You have a typo. Your list is named geusses and than you try to add elements to list named guesses.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Phantoms |
