0

So I have code, where it should choose at random whether to show the user the entry itself or the associated definition.

from random import *


def show_flashcard():

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

glossary = {'word1':'definition1',
            'word2':'definition2',
            'word3':'definition3'}

It only shows the random keys, but not the values. How can i implement this in my code ?

MisterMiyagi
  • 44,374
  • 10
  • 104
  • 119
  • I cannot reproduce the issue with the code shown. The code will either show nothing at all (with the code as is) or show the key and then the definition (when calling `show_flashcard`). Do you actually press return when given the prompt? Please take a look at the [mre] help page and [edit] the question accordingly; in specific, provide code that reproduces the issue as-is and describe what happens and what you expected instead. – MisterMiyagi Sep 06 '22 at 13:25
  • And also, how to combine them all in one def function??? – ohboyitshard Sep 06 '22 at 13:27

1 Answers1

-1

With choice(list(glossary.values())), you can get a random value from your dict.

Happy Ahmad
  • 1,072
  • 2
  • 14
  • 33