简体   繁体   English

如何使输入接受括号中的任何形式的单词?

[英]How can I make the input accept any form of the words in the brackets?

So, Im very new in python and in programming in general and I'm watching some tutorials to acquire knowledge in the field of python and i want to ask how can i make the input accept any way that the words in the brackets are written enter image description here所以,我在 python 和一般编程方面非常新,我正在观看一些教程以获取 python 领域的知识,我想问一下如何让输入接受括号中的单词写入的任何方式输入图片说明在这里

so as you can see the code only accepts Yes or No as answers but in case of someone mistakenly instead of writing Yes or No writes yEs or nO or YEs or NO or any other way its possible to mistakenly wirte it to be accepted?所以你可以看到代码只接受是或否作为答案,但如果有人错误地写是或否而不是写yEs或nO或YEs或NO或任何其他可能错误地写它被接受的方式?

You can use the lower() function to convert any string to lowercase and then compare them, eg:您可以使用 lower() function 将任何字符串转换为小写,然后进行比较,例如:

list = ["yes", "no"]
word = input()
if word.lower() in list:
    print("OK")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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