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

标签 python

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

相关文章:

python - scipy的构建轮(setup.py):状态为 'error'

python - 电影推荐中的预测值

python - 对于 celery worker 来说,禁止八卦、交流和心跳会产生什么后果?

python - numpy isnan 的有效等价物或查看 N 值窗口的地方

python - 删除所有列中具有相同值的行

python - 使用 setuptools 创建 python 可执行文件

Python比较两个不同列表中的元素

python - 如何在 tkinter 中查看 TreeView 的部分区域和水平滚动?

Python - 字符串中的逗号导致 strip 出现问题

python - 插入mysql语法错误