a = int(input("Enter choice: "))
if a > 3 and a < 1: #the issue is here how can i rewrite it to allow this?
print("Invalid choice")
else:
print("Correct choice")
如您所见,我希望它允许“a”小于 1 且大于 3,但我的写法不起作用。
最佳答案
你使用了错误的条件。
要检查是否满足任一条件,请使用或
:
if a > 3 or a < 1:
要检查是否满足两个条件(当然,在这种情况下永远不可能),您可以使用and
。
关于python - 如何在 python 上同时将 if 语句设置为小于和大于?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54918756/