问题
I want my Python code to accept both uppercase and lowercase input.
I've tried casefold, but with no luck. Any help?
advice =""
while advice !=("Yes"):
print("Would you like some advice!")
advice = input("Yes or No? ")
print("Always listen to your IT Teacher!")
I would like the input to accept Yes
and yes
as user input.
回答1:
You could just make advice uppercase eg.:
while advice.upper() != "YES"
This way it doesn't matter if the user inputs lower or upper case (or a mix).
来源:https://stackoverflow.com/questions/28406568/need-python-to-accept-upper-and-lower-case-input