Logic problem 13 of 30

De Morgan's laws

  • Logic
  • Medium

Rewrite this condition without using not, so that it means exactly the same thing:

if not (x > 0 and x < 10):
    print("out of range")
Show hint

"Not (A and B)" is the same as "(not A) or (not B)". What is the opposite of x > 0?

Show solution

if x <= 0 or x >= 10:

De Morgan's laws say not (A and B) equals (not A) or (not B), and not (A or B) equals (not A) and (not B). The opposite of x > 0 is x <= 0, not x < 0. Getting that edge wrong is a classic off-by-one bug.

Want a problem like this every day? See today's problem and keep a streak going.