-1

I'm having trouble understanding my logic in a simple Python statement. I'm trying to use 'not in' to test whether 's' or '5' is a part of the input but when I use either of them the same print statement is executed which says 's or 5 is not included'. Here is my code:

myinput = input('Enter input here')
if 's' or '5' not in myinput:
    print('s or 5 is not included')
else:
    print('s or 5 is included')

Could someone help me out? Thanks

podjv
  • 3
  • 2

2 Answers2

0

(Am certain this is a duplicate, but could not find it.)

"Neither 's' nor '5' are in myinput" is logically equivalent to "('s' is not in myinput) and ('5' is not in myinput)". (See DeMorgan's Law.)

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
0

As stated by Scott Hunter

if ('s' not in myinput) and ('5' not in myinput):
    print('s or 5 is not included')
else:
    print('s or 5 is included')

De Morgan's law states that not (A or B) = not A and not B

In your example, A = 's' is in myinput, and B = '5' is in myinput

oamandawi
  • 405
  • 5
  • 15