Ad

Error Message Comes Up Even If Input Is Correct. Python

- 1 answer

I am trying to allow certain input with this code.

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

If I input 45 or 38 print("depth can only be 45 or 38") is output when it should not.

Ad

Answer

You need and, not or in this case. For example, if you enter 45, Sdepth != 38 is still True, thus the whole if condition is True. Or you can use if Sdepth not in (45, 38):

Ad
source: stackoverflow.com
Ad