我正在尝试使用此代码允许某些输入。
Sdepth = int(input("enter depth of slab: "))
if Sdepth != 45 or Sdepth != 38 :
print("depth can only be 45 or 38")
Sdepth = int(input("enter depth of slab: "))
如果我输入 45 或 38 print("深度只能是 45 或 38")
会输出,但不应该输出。
最佳答案
您需要and
,不是or
在这种情况下。例如,如果您输入 45
, Sdepth != 38
仍然是True
,因此整个 if 条件为 True
。或者您可以使用 if Sdepth not in (45, 38):
关于python - 即使输入正确也会出现错误消息。 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58197948/