2

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.

1
  • 1
    If Sdepth is 45, it is still not 38. You mean and, not or. Commented Oct 2, 2019 at 8:33

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

Sdepth != 45 or Sdepth != 38 evaluates to True if either or Sdepth != 45 or Sdepth != 38 is True. If Sdepth is 38, then Sdepth != 45 is True.

Change the if line to this:

if Sdepth not in [38, 45]:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.