[Solved] Why doesn’t this “is not” if statement work?


To apply the logic of “not any” you would want to check if it is any of the valid results then invert. (NOR)

if not (diff == "1" or diff == "2" or diff == "3"):

Or applying DeMorgan’s theorem this would be equivelent to “not equal to 1 AND not equal to 2 AND not equal to 3”

if diff != "1" and diff != "2" and diff != "3":

of course python also has the in and not in operator which makes this much cleaner:

if diff not in ("1", "2", "3"):

solved Why doesn’t this “is not” if statement work?