0

Hi, I have been learning Python and have a quick dictionary question.

I am trying to make a "vocabulary test" to help myself study, and am trying to do it with a dictionary. So far I have this:

testwords = {"uno":"one","dos":"two","tres":"three","cuatro":"four",\
             "cinco":"five"}

def vocabtest():
    for value in testwords:
        print "What word does the following definition correspond with?"
        print value
        answer = raw_input("> ")
        if answer == :
            print "Correct!"

vocabtest()

I need help with line 9, "if answer == :".
I am not sure how I would check to see if the user's answer is equal to the corresponding key.

Any help would be greatly appreciated. Thanks.

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by SoulMazer
0

An appropriate variable name in the for loop would be key instead of value, because you are iterating on the keys of the dictionary.

if answer == testwords[key]:
1

I guess you want to write this

def vocabtest():
    for value in testwords:
        print "What word does the following definition correspond with?"
        print value
        answer = raw_input("> ")
        if (answer == testwords[value]):
          print "Correct!"
        else:
          print "No the answer is ",testwords[value]
Votes + Comments
Perfect answer.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.