我不是专家或者只是初学者,但我在检查某个值时遇到问题,看它是否对文件是正确的,这是我现在的代码
line = open("question.txt", "r").readlines()[0]
secondline = open("answer.txt", "r").readlines()[0]
print("Please enter A or B for the correct answer")
answer = input("What does "+ line + " mean? \n A: set of rules \n B: a
program ").upper()
if answer == (secondline):
print("Well done")
else:
print("incorrect")
what outputs is:
Please enter A or B for the correct answer
What does algorithm mean?
A: set of rules
B: a program a
incorrect
>>>
'问题'文本文件仅包含第一行的算法 并且'回答'文本文件在第一行只有'a'。
请帮忙!谢谢。
答案 0 :(得分:0)
要使此代码生效,您可以将upper()
替换为lower()
,或将answer.txt的内容更改为A
。