我正在寻找一个基于 Python 的词汇检查器,供我的小表弟用来学习。该程序的目的是显示一个单词,然后她需要输入定义并检查它。我想知道最好的方法是使用数组列表:
vocab = ['Python','OSX']
definition = ['programming language','operating system']
这是解决这个问题的最好方法吗?如果是这样,我如何让程序随机显示一个词汇,然后检查定义。任何帮助将不胜感激。感谢你们。
好的。所以这就是我到目前为止所拥有的......#Russian Translation Program
import os
import random
#Asks users if they want to add more vocabulary
word_adder=raw_input("Add more words? If yes, press 1: ")
with open("Russian_study.txt","a") as f:
while word_adder=="1":
word=raw_input("Enter word: ")
translation=raw_input("Word translation: ")
f.write("'{0}':{1},".format(word,translation))
word_adder=raw_input("Add another word? If yes, press 1: ")
#Checks to see if file exists, if not one is created
with open("Russian_study.txt","a") as f:
pass
os.system('clear')
print("Begin Quiz")
#Begin testing user
with open("Russian_study.txt","r") as f:
from random import choice
question = choice(list(f))
result = raw_input('{0} is '.format(question))
print('Correct' if result==f[question] else ':(')
但是,我的输出是
Begin Quiz
'Один':'One', is
如何让它只显示Один并检查用户输入?