好的。所以这就是我到目前为止所拥有的......#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},/n".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, answer = choice(list(f)).split(':')
result = raw_input('{0} is '.format(question))
print('Correct' if result==answer else ':(')
该程序有效,但是,当添加多个条目时,它总是显示不正确。有什么帮助吗?此外,它在一个问题后停止运行,永远不会进入下一个问题......