Your code could be a lot more readable if you restructured it slightly. Using DeMorgan’s laws we have that not A and not B and not C
is the same as not (A or B or C)
. And since A or B or C
is the same as any([A,B,C])
we can just take your first while
and rewrite it as
while not any([ condition == 1,
condition1 > x,
condition2 > y ]):
print("Hey")
We can see immediately why the loop isn’t running because one of those is True
. Namely condition1
(which is 3) is greater than x
(which is 2).
Similarly if we consider the second while
loop rewritten as
while not any([ condition == 1,
condition1 > x ]):
print("Hey")
Since condition
equals 1, it fails on the first predicate. And even if condition
didn’t equal 1, condition1
(which is 3) is greater than x
(which is 2). So the second predicate also fails.
solved Python – while loop three conditions [closed]