需要Python接受大小写输入 [英] Need Python to accept upper and lower case input

查看:125
本文介绍了需要Python接受大小写输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Python代码同时接受大写和小写输入。

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.

推荐答案

您可以将建议大写,例如:

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

这篇关于需要Python接受大小写输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆