-2

I was trying to create "not equal to N or n" to allow for different inputs, and have created a logic that allows all selections to pass. Is my logic wrong, or my coding?

item = input()
if item != "N" or item != "n":
    print("Inside loop - {0} not like N or n".format(item))
else: print("outside loop - {0}  like N or n".format(item))
dogwood
  • 9
  • 4
  • 2
    Not sure if the logic or the coding is wrong, but one of the two is wrong. I think you meant `if item != 'N' and item != 'n'` which is equivalent to `if not (item == 'N' or item 'n')` ([De Morgan's laws](https://en.wikipedia.org/wiki/De_Morgan%27s_laws)). – mkrieger1 Oct 09 '20 at 21:09

1 Answers1

4

A little of both -- your or isn't testing "not equal to N or n", it's testing "(not equal to N) or (not equal to n)". You want something more like:

if item not in ("N", "n")

or:

if item != "N" and item != "n"

or maybe just:

if item.lower() != "n"
Samwise
  • 68,105
  • 3
  • 30
  • 44