好的。因此,這是我迄今爲止.... #Russian翻譯課程翻譯計劃
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 ':(')
這個程序工作,但是,當添加多個條目總是顯示不正確的。任何幫助?此外,它在一個問題後停止運行,從未進入下一個問題....
哈,你剛纔打我給它。 – Ewan 2013-05-08 06:34:59
輸入,不起作用。它僅在使用raw_input時運行。 – h3tr1ck 2013-05-08 06:36:58
這很奇怪。我安裝了Python 3.3.1,並沒有''raw_input()''那裏。另外,http://docs.python.org/3/library/functions.html中沒有提到''raw_input()''。 – fjarri 2013-05-08 06:39:59