Python正确答案显示错误

时间:2015-03-01 11:42:37

标签: python file

我正在查看一些问题游戏的代码,其中的答案是从文件中读取的,但是当我运行它时,它告诉我答案是错的,即使它是对的,我输入错了还是在那里文本文件中缺少什么?

for line in lines:
question, rightAnswer = line.strip().split("\t")
answer = input(question + " ")
if answer.lower() == rightAnswer:
    print("Right!")
    numRight = numRight + 1
else:
    print("No, the correct answer is %s" % rightAnswer)

我的文本文件如下:

How many strings does a guitar have?    Six
How many strings does a violin have?    Four
Are mandolin strings in pairs?  Yes

1 个答案:

答案 0 :(得分:4)

if answer.lower() == rightAnswer更改为if answer.lower() == rightAnswer.lower()