首页 > 解决方案 > 即使条件为假,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')

标签: python-3.x

解决方案


尝试这样的事情

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

推荐阅读