我想尝试这个抽认卡的想法来尝试学习关键字及其含义,以备将来的测试使用。我想在 python 上创建一个字典,我可以用它来帮助解决这个问题。这个想法是向我展示定义,然后我必须猜测已定义的单词。我已经在下面展示了如何做到这一点,首先显示键然后显示值,但我希望它做相反的事情,但无法弄清楚如何实现这一点。(下面代码中的词汇表是指我的字典)任何帮助将不胜感激。
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])
Run Code Online (Sandbox Code Playgroud)
如果我理解正确的话,这还不够吗?
print('Define: ', glossary[random_key])
input('Press return to see the definition')
print(random_key)
Run Code Online (Sandbox Code Playgroud)
基本上只是交换问题和答案。
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |