kind of stuck with this code. I'm trying to print keys or values in random order from the dictionary. (Randomly whether to show the entry first or the corresponding definition) But I'm getting only a key first followed by a value. What I'm missing for the code to work? Any help will be amazing. Thank You Example:
- Test-1 (Pressing Return Key) Definition-1
- Definition-4 (Pressing Return Key) Test-4
- Definition-2 (Pressing Return Key) Test-2
- Test-3(Pressing Return Key) Definition-3 ...
from random import *
def flashcard():
random_key = choice(list(dictionary))
print('Define: ', random_key)
input('Press return to see the definition')
print(dictionary[random_key])
dictionary = {'Test-1':'Definition-1',
'Test-2':'Definition-2',
'Test-3':'Definition-3',
'Test-4':'Definition-4'}
exit = False while not exit:
user_input = input('Enter s to show a flashcard and q to quit: ')
if user_input == 'q':
exit = True
elif user_input == 's':
flashcard()
else:
print('You need to enter either q or s.')