Need Python to accept upper and lower case input

老子叫甜甜 提交于 2019-12-13 09:22:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!