有点被这个代码束缚住了. 我正在try 以随机顺序打印词典中的键或值. (随机是先显示条目还是显示对应的定义) 但我只得到一个键,后跟一个值. 我遗漏了什么才能让代码正常工作? 任何帮助都会令人惊叹.谢谢 示例:
- 测试-1(按回车键)定义-1
- 定义-4(按回车键)测试-4
- 定义-2(按回车键)测试-2
- 测试-3(按Return键)定义-3...
从随机导入*
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.')