gpt4 book ai didi

python - 如果输入不区分大小写,则更改 Python

转载 作者:太空宇宙 更新时间:2023-11-03 12:58:46 25 4
gpt4 key购买 nike

我在学校,由于我们是相当年轻的学生,我的一些“同事”不了解什么是区分大小写。我们正在用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com