For reference, I am using Python 3.0. So, I have a small script I am working on trying to improve. I am now trying to create it with only dictionaries and loops.
My problem is that I keep getting a Key Error at one of my lines. The line with the error has an "Error" comment. Also, "words" is a dictionary. And yes, I struggle with dictionaries.
Code:
def vocabtest():
for r in words.values():
count = 0
while count < 3:
print("What word does the following definition correspond with?")
print(r)
answer = input("> ")
if answer == words[r]: #Error
print("Correct!")
count = 100000
elif count < 2:
count = count + 1
print("That is incorrect. Try again.")
elif count == 2:
count = count + 1
print("That is incorrect. The answer was",str(words[r]) + ".")
fail[r] = words[r]
If it is not obvious, I am printing the definition of the word, and requesting the user to input the word that matches the definition.
Any help to what is the cause of my error would be greatly appreciated. Thanks.