如何使用OR语句来比较整数(python)


phoneMinutes = int(input("Please enter your desired call minutes."))
if phoneMinutes != 100 or 200 or 300: 
print("false")
else:
print("true")

我正试图使这个程序输出";真";如果变量phoneMinutes等于100、200或300;false";。然而,一旦我开始使用or语句,每次运行程序时,输出都是";false";。不太确定这里出了什么问题,所以欢迎提出任何建议。

if phoneMinutes != 100 or 200 or 300:这不是正确的语法;这与CCD_ 2类似。200是一个真实的价值,所以它永远都是真实的。你想要if phoneMinitues != 100 or phoneMinutes != 200 or phoneMinutes != 300:是一种快速而肮脏的方式。

最新更新