One condition is fine, but real rules stack them: over a height and either with an adult or old enough. Today you join Booleans together with and, or, and not.
Covers and, or, and not and how they combine.
Enrolled in our Runestone course? Open it from there so your progress counts.
Still in Programs, closing out Week 3’s teach days. You can build one Boolean (2.11) and act on it (2.12–2.13). Today you combine several Booleans into a single compound condition — the last piece before Decision Day.
and, an or, and parentheses that change the meaning — exactly the
structure the exam tests.
Read it carefully: the height rule is
non-negotiable (it’s joined by and), but the second half offers two ways to
qualify (joined by or). Miss the parentheses and you’d let a 40-inch kid ride
just for being over 12. Logic operators are how a program gets rules like this exactly right.
Three logical operators combine Booleans into one:
| Operator | Python | Pseudocode | True when… |
|---|---|---|---|
| both must hold | and | AND | both sides are True |
| either will do | or | OR | at least one side is True |
| flip it | not | NOT | the one side is False |
The clearest way to nail these down is a truth table — every combination of inputs and the result:
| A | B | A and B | A or B | not A |
|---|---|---|---|---|
| True | True | True | True | False |
| True | False | False | True | False |
| False | True | False | True | True |
| False | False | False | False | True |
height = 50 with_adult = False age = 13 can_ride = height >= 48 and (with_adult or age > 12) print(can_ride) # True
height ← 50 withAdult ← false age ← 13 canRide ← height ≥ 48 AND (withAdult OR age > 12) DISPLAY(canRide)
Hover or tap a line to light its twin. Trace line 4:
50 >= 48 is True; the parentheses give (False or True) = True;
True and True = True. Drop the age > 12 to 10 and the
whole thing flips to False — try it in the machine below.
and turns it into
an or. You’ll meet this formally later; for now, just don’t assume
“not” distributes without changing the connector.
Set the three inputs and watch each piece of the compound condition evaluate, then combine. This is the amusement-park sign as running code.
and, or,
not (AND, OR, NOT in pseudocode).Six questions. Evaluate the inside of the parentheses first, then combine — on paper — then pick your answer.
and, or, and not
aren’t just code — they’re the logic behind every search box and filter you use.
“Show me shoes that are size 10 and under $80 and (blue or
black).” A spam filter, a database query, a content moderation rule — all of it is
compound Boolean conditions deciding what you see and what you don’t.
Deep down, these same three operations are also how the physical chips
in every device compute — logic gates wired from AND, OR, and
NOT. You’re learning at the software level the exact idea the hardware is built
from. It really is operators all the way down.
if can test.AND/OR/NOT
expressions, especially with parentheses, is a guaranteed and very learnable point source.