Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a simpler condition, without a not in front of a bracket, that is the same as each of these:
not (age >= 18 and has_ticket)not (x > 5 or y > 5)not (a == b)Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Use the rule of not: when not goes inside the bracket, and becomes or, and or becomes and. Absorb a not in front of a comparison into the comparison.
not (age >= 18 and has_ticket) becomes (not age >= 18) or (not has_ticket), that is age < 18 or not has_ticket.not (x > 5 or y > 5) becomes (not x > 5) and (not y > 5), that is x <= 5 and y <= 5.not (a == b) is a != b.Check (1). Take age = 20 and has_ticket = False. The original is not (True and False), which is not False, so True. The simple form is False or not False, which is False or True, so True. The same. Try the other three combinations to be sure.
Answer: age < 18 or not has_ticket; x <= 5 and y <= 5; a != b.
Log in to join the discussion.
Loading…