我正在尝试创建一个测验程序,从一个文件中读取问题,同时从另一个文件中读取正确的答案。目前我的程序不打印问题或答案,也没有提供任何错误信息,让我感到困惑...... 请原谅我的新手代码,因为我真的很感激任何帮助! :)
def quiz():
score = 0
time.sleep(1)
topic = input ("Please choose the topic for the quiz. The topics available are: \n- Computer Science \n- History \n Please enter in lower case.\n - ")
difficulty = input("Please choose the diffilculty. The difficulties available are: \n- Easy \n- Hard \n- ")
i = 0
for i in range(0,4):
with open(topic+" "+difficulty+".txt", "r") as questions:
question = questions.readline(i)
print(question)
time.sleep(0.9)
#questions.close
with open (topic+" "+difficulty+" answers.txt", "r") as answers:
answer = answers.readline(i)
print(answer)
#answers.close
userAns = input()
#questions.close
#answers.close
i = i + 1
if userAns == answer:
score = score + 1
return score