I'm writing a function to see if a user's input is in a list, if it is the users input is removed and they are asked to guess again until they quit.
I want to count the number of correct guesses and print it after the function is called, for some reason, regardless of the number of correct guesses it prints zero. What have I done wrong? (Code and example below)
# [ ] Complete Foot Bones Quiz
foot_bones = ["calcaneus", "talus", "cuboid", "navicular", "lateral cuneiform","intermediate cuneiform", "medial cuneiform"]
guess =''
already_guessed = []
def foot_bone_quiz(guess, foot_bones):
correct_guess = 0
while True:
guess = input("Guess a foot bone, enter q to quit. ")
if guess.lower() in already_guessed:
print("You already guessed that!")
elif guess != 'q':
for bone in foot_bones:
if bone.lower() == guess.lower():
correct_guess = correct_guess + 1
print("Yes", guess, "is a bone in the foot!")
already_guessed.append(guess.lower())
foot_bones.remove(guess.lower())
else:
pass
elif guess == 'q':
print('finished')
break
else:
print("Invalid Entry")
return already_guessed, correct_guess
foot_bone_quiz(guess, foot_bones)
print("You had", correct_guess, "correct guesses. You guessed: ", already_guessed)
Example output:
Guess a foot bone, enter q to quit. navicular
Yes navicular is a bone in the foot!
Guess a foot bone, enter q to quit. talus
Yes talus is a bone in the foot!
Guess a foot bone, enter q to quit. q
finished
You had 0 correct guesses. You guessed: ['navicular', 'talus']