我在学校,由于我们是相当年轻的学生,我的一些“同事”不了解什么是区分大小写。我们正在用 Python 做一个测验。这是代码:
score = 0 #this defines variable score, and sets it as zero
print("What is the capital of the UK?")
answer = input ()
if answer == "London":
print("Well done")
score = score + 1 #this increases score by one
else:
print("Sorry the answer was London")
print("What is the capital of France?")
answer = input ()
if answer == "Paris":
print("Well done")
score = score + 1 #this increases score by one
else:
print("Sorry the answer was Paris")
print("Your score was ",score)
他们输入“伦敦”而不是“伦敦”作为答案,但仍然得到错误的答案。任何解决方法?
最佳答案
您可以使用 .upper()
或 .lower()
if answer.lower() == 'london':
关于python - 如果输入不区分大小写,则更改 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30123112/