简体   繁体   中英

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

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?

You can use the lower() function to convert any string to lowercase and then compare them, eg:

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

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