简体   繁体   中英

Python right answer shows as wrong

I was looking at some code for a question game where the answers are read from a file, but when I run it, it tells me the answer is wrong even if it is right, have I typed it up wrong or is there something missing in the text 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)

My text file is as follows:

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

if answer.lower() == rightAnswerif answer.lower() == rightAnswer.lower()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM