Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
277 views
Welcome To Ask or Share your Answers For Others

1 Answer

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...