Search code examples
pythonlogic

Python - Logic of Not Equal Or - lets all selections pass


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

Solution

  • 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"