Every program that makes a choice is secretly asking yes/no questions. Today you meet the two answers a computer can give — and the one-character typo that breaks more beginner programs than anything else.
Covers Boolean values and comparison operators — the raw material for everything in Week 3. Enrolled in our Runestone course? Open it from there so your progress counts.
Still in Programs, opening Week 3. For two weeks your programs ran the same way every time. This week they start making decisions — and a decision needs a yes/no question to decide on. That question is today.
Each question has exactly one of two answers — True or False. Those two words are a whole data type, named after George Boole, and once you can produce them on purpose you can make a program choose.
A Boolean value is one of exactly two things: True or
False (capital first letter in Python, always). A Boolean expression
is any expression that evaluates to one of those two — usually by comparing two
values with a comparison operator.
| Question | Python | AP Pseudocode | Example |
|---|---|---|---|
| equal to? | == | = | 7 == 7 → True |
| not equal to? | != | ≠ | 5 != 5 → False |
| less than? | < | < | 3 < 8 → True |
| greater than? | > | > | 3 > 8 → False |
| less than or equal? | <= | ≤ | 3 <= 3 → True |
| greater than or equal? | >= | ≥ | 6 >= 6 → True |
= means
assign (“put this value in the box”). == means
compare (“are these two equal?”). Writing if x = 5 when you
meant if x == 5 is the single most common mistake in Week 3. When you compare,
you need two equals signs.
age = 16 # one = : assignment can_drive = age >= 16 # a Boolean print(can_drive) # True print(age == 18) # two == : compare
age ← 16 canDrive ← age ≥ 16 DISPLAY(canDrive) DISPLAY(age = 18)
Hover or tap a line to light its twin. Notice the flip: pseudocode uses a
single = for the comparison that Python writes as ==, and a left arrow
← for the assignment Python writes as =. Read both; write Python.
"cat" == "Cat" is False, because a capital C is a different
character (a different bit pattern — remember Unit 1) than a lowercase c.
n % 2 == 0 — “is n even?” It reads right to left: first compute
n % 2 (the remainder), then compare that to 0. You met MOD in 2.3;
here it becomes a yes/no question.
Pick two numbers and an operator. The machine shows you the Boolean expression and the single value it evaluates to. Predict the answer before you read it.
True or False. Named after
mathematician George Boole.True or False — usually a
comparison like age >= 16.==, !=, <, >, <=,
>=.Six questions. Evaluate each expression on paper first — that’s the exam skill. Pick an answer for instant feedback.
It is a genuinely strange fact that all of computing’s decisions — a self-driving car braking, a bank flagging a charge, a spam filter, a medical alert — bottom out in expressions that are only ever True or False. There is no “maybe” at this level. Complexity comes from combining thousands of these tiny yes/no answers, not from any single one being clever.
That is also where bias can hide. A loan program that decides with
income >= threshold looks neutral, but someone chose the threshold. The
Boolean is honest about being a rule; whether the rule is fair is a human question the code
can’t answer. You’ll come back to this in Unit 8.
n % 2 was just a number. Compare it to
0 and it becomes the yes/no question “is n even?”if
and the program finally acts on the answer.and, or, and not to ask compound questions.= vs ==, are guaranteed multiple-choice points.