0

Can this be shortened?

Ok, I am completely new to computer coding, and I have been learning python through this amazing app and website for less than a month. Now I have a question about something I am putting together. Here is the code: x = input("Do you want to try again? Yes or no? ") if x == "yes": print("\n") continue elif x=="YES": print("\n") continue elif x=="Yes": print("\n") continue elif x=="YEs": print("\n") continue elif x=="YeS": print("\n") continue elif x=="yES": print("\n") continue else: print("\n") print("Okay, that's fine, but don't ask again.") break As you can see I am trying to accept all forms of "yes" no matter how the user inputs it. Is there an easier way to do this, or do developers have to put in every form of an answer? If that doesn't make sense, what if I wanted to accept "sure" as an acceptable answer would I have to do another elif: for that too? Thanks in advance

20th Jul 2018, 6:53 PM
sneakysnek
sneakysnek - avatar
2 RĂ©ponses
+ 2
Strings have a .lower() method that makes all the characters lower case so x = input() if x.lower() == "yes": #code elif x.lower() == "no": #code else: #code
20th Jul 2018, 7:00 PM
TurtleShell
TurtleShell - avatar
+ 1
Thank you! I covered that part too haha But I am learning
20th Jul 2018, 7:13 PM
sneakysnek
sneakysnek - avatar