What is the conditional order for checking if two pairs of things are true?

25 Views Asked by At

I have two parameters, a and b. There are two possible sets of values that if both of them is not true, I want to raise a warning. For example, I might want to raise a warning if both a=1 and b=1 is not true AND if both a=2 and b=2 is not true, but if one of the conditions (e.g. a=1 and b=1) is true I don't want to raise the warning. I'm not sure how to get the logic correct for this - I have tried

if not a == 1 and b == 1 or a == 2 and b == 2:
 #some warning

but this doesn't seem to be correct.

1

There are 1 best solutions below

0
On

you should put brackets on your condition to be like this: if not (a==1 and b==1) or (a==2 and bee2) #some warning I suggest changing the logic to this: if (a!=1 and b!=1) or (a==2 and b==2) instead. I also recommended learning about de morgan laws from here: https://en.wikipedia.org/wiki/De_Morgan%27s_laws and calculate truth table for your conditions.