1

I want to try this flashcard idea to try and learn keywords and their meanings for an upcoming test. I want create a dictionary on python which I can use to help with this. The idea is that the definition is shown to me and then I have to guess the word that has been defined. I have shown below how to do it where the key is shown first then the value but I want it to do the opposite but can't figure out how to implement this. (The glossary in the code below refers to my dictionary) Any help would be appreciated.

def show_flashcard():
    """ Show a random key and ask me
        to define it. Show the definition
        when the user presses return.    
    """
    random_key = choice(list(glossary))
    print('Define: ', random_key)
    input('Press return to see the definition')
    print(glossary[random_key])
DjaouadNM
  • 22,013
  • 4
  • 33
  • 55

2 Answers2

5

If I understand you correctly, shouldn't this suffice?

print('Define: ', glossary[random_key])
input('Press return to see the definition')
print(random_key)

Essentially just switch the question and the answer.

Taxel
  • 3,859
  • 1
  • 18
  • 40
2

you can try:

def show_flashcard():
    """ Show a random definition and ask me
        the key. Show the key
        when the user presses return.    
    """
    random_key, random_def = choice(list(glossary.items()))
    print('Define: ', random_def)
    input('Press return to see the key')
    print(random_key)
kederrac
  • 16,819
  • 6
  • 32
  • 55