I am seriously under-slept and I need help in rewriting this small Python piece of logic
for _ in range(100):
if a:
continue
elif b:
continue
elif c and d:
continue
else:
e()
I want to have something like
if (some_exprt of a,b,c,d):
e()
What I got is:
if not a and not b and (not c or not d):
e()
but I really can't tell if this is correct or not, am I right?
Start with under what conditions the
else
branch would not match. It'd be one ofa
, orb
, orc and d
, so you would need to useor
andnot
here to express when theelse
branch of your original code would be picked:You could then bring the
not
into the parenthesis by applying one of De Morgan's laws, expressing the preceding test more verbosely as:which could then be further expanded to:
which is what you yourself already expanded to. But I'd find the first version to be more readable.