python-3.x - 即使条件为假,Python 中的“或”语句也会计算为真
问题描述
即使我提供除 1,2 或 3 之外的任何其他值,此逻辑 OR 的计算结果仍为 true。
在我开始学习 Python 时请帮助解决这个问题
user_input=int(input('Please provide Size of coffee: (1-small/2-medium/3-large)'))
if user_input!=1 or user_input!=2 or user_input!=3:
print('Please input 1,2 or 3')
解决方案
尝试这样的事情
user_input=int(input('Please provide Size of coffee: (1-small/2-medium/3-large)'))
if user_input not in (1, 2, 3):
print('Please input 1,2 or 3')
else:
print('Thanks... {} coming up'.format(user_input))
推荐阅读
- logging - Kotlin Basics:打印相同的字符串两次以上
- python - 如何使用 Dlib 性别/年龄模型?“.dat 文件”
- android - 测试接口库
- django - int() 参数必须是字符串、类似字节的对象或数字,而不是“ForeignKey”
- nginx - 如何配置在 Kubernetes 中运行的 Nginx WSS
- python - 如何在训练过程后找出模型的验证准确度?
- javascript - 将javascript onclick事件添加到php数组?
- html - 如何使用注入的Javascript获取html代码 - React-native
- python - 如何从 pandas Dataframe groupby 对象中获取一系列 json/字典
- google-app-engine - 在 Google Cloud App Engine 或 Compute Engine VM 实例 Ubuntu 18.04 LTS 上启动 Web 应用程序