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,但我写的方式不起作用。
您正在使用错误的条件。
要检查是否满足是否满足条件,请使用or
:
if a > 3 or a < 1:
检查是否满足是否满足了两个条件(当然,在这种情况下是不可能的),您使用and
。
您可以以相反的方式链接条件:
if 1 <= a <= 3:
print("Correct choice")
else:
print("Invalid choice")