Home > OS >  How can I make the input accept any form of the words in the brackets?
How can I make the input accept any form of the words in the brackets?

Time:04-20

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?

CodePudding user response:

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")
  • Related