Week 4 — Lecture Outline · Booleans & Conditionals
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective covered: Objective 3 — Use Boolean logic and conditionals — the bool type, comparison and logical operators, truth tables, and if/elif/else — to make programs decide, and trace which branch runs.
SLOs touched: A (write and run a correct decision program) · B (trace Boolean expressions and branches; find and fix a =-vs-== or elif-order defect)
Meeting pattern: 2 studio sessions × 75 min = 150 min. Segment minutes below total ~150; scale to your own pattern.
Every Boolean result, traced value, branch outcome, and error message in this outline was produced by actually running the code in Python — not hand-traced. Run them live in class; the outputs are exact.
Week at a Glance
| The week's big question | "How does a program make a decision — and how do you control exactly which code runs?" |
| By the end of the week, students can… | (1) evaluate Boolean expressions with comparison (==, !=, <, >, <=, >=) and logical (and, or, not) operators and predict the True/False result; (2) read and build a truth table and apply the precedence not → and → or; (3) write an if/elif/else and trace which branch runs; (4) spot and fix the = vs == bug and an out-of-order elif chain. |
| Key vocabulary | bool, True, False, Boolean expression, condition, comparison operator, ==, !=, <, >, <=, >=, logical operator, and, or, not, operator precedence, truth table, conditional, if, elif, else, branch, indentation/block, falsy/truthy, SyntaxError |
| Materials | slides (Deck 4), the week's readings + video links, a free online Python environment + Python Tutor (links in the readings), one approved chatbot (Gemini / Claude / ChatGPT) for the AI-critique moment and the tutorial |
| Timing note | 8 segments, ~150 min total. Session 1 = Segments 1–4 (~75). Session 2 = Segments 5–8 (~75). This is a studio: code along on the projector and have students type every example into the online environment with you, and run every Boolean to confirm the value. |
Segment 1 — Hook & the Promise (8 min) · Session 1 opens
Hook. Put a turnstile photo (or just the words) on a slide: "$8 if you're under 18, otherwise $12." Ask: "How does the ticket machine know which price to charge?" Take a couple of answers. Land it: the machine asks a yes/no question about your age and runs different code depending on the answer. That yes/no — True or False — is the whole idea this week. Every app that greets you by name only if you're logged in, every form that rejects a weak password, every game that says "you win" — all of it is a program deciding.
The promise (write it on the board): "By Friday you'll write a program that gives different answers for different inputs — and you'll meet the most famous beginner trap in Python: = versus ==."
Why it matters line (memory hook): "= puts a value IN; == ASKS a question."
Segment 2 — Booleans & Comparisons: the bool Type (20 min)
Plain language first. So far our values have been numbers (int, float) and text (str). Today's new type is the bool — and it has exactly two values: True and False (capital T, capital F, no quotes — they're not strings). A Boolean expression is any expression that evaluates to one of those two values. It's how a program represents a yes/no answer.
Where Booleans come from — comparison operators (code-along; everyone types and runs each):
print(5 == 5)
print(5 == 6)
Output (run-verified):
True
False
"== asks: are these equal? It answers True or False. Notice the double equals — we'll come back to why that matters, hard."
The six comparison operators, run one at a time:
print(5 != 6) # not equal
print(3 < 5) # less than
print(3 > 5) # greater than
print(5 <= 5) # less than OR equal
print(7 >= 10) # greater than OR equal
Output (run-verified):
True
True
False
True
False
"Each one is a question. Each one answers with a Boolean. <= means 'less than or equal,' so 5 <= 5 is True."
Comparisons work on strings too (run-verified):
print("cat" == "cat")
print("Cat" == "cat")
Output:
True
False
"Strings compare character by character — and Python is case-sensitive, so Cat and cat are not equal. Same case-sensitivity lesson from Week 1, new context."
You can store a Boolean in a variable (run-verified):
is_adult = 20 >= 18
print(is_adult)
Output:
True
"The comparison runs first, producing True, and that gets stored in is_adult. Now the program 'remembers' the answer."
Segment 3 — Logical Operators & Truth Tables: and / or / not (24 min) · the code-along + worked trace
Plain language first. Often one yes/no isn't enough — you need to combine them. "Are you 18 or older and do you have a ticket?" Python gives us three logical operators: and, or, not.
and→Trueonly when both sides areTrue.or→Truewhen at least one side isTrue.not→ flips it:not TrueisFalse,not FalseisTrue.
Build the truth tables live (everyone types and runs each line):
print(True and True)
print(True and False)
print(False and True)
print(False and False)
Output (run-verified):
True
False
False
False
print(True or False)
print(False or False)
Output (run-verified):
True
False
print(not True)
print(not False)
Output (run-verified):
False
True
Put the collected truth table on a slide:
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 |
Worked trace #1 — a combined expression (reveal one piece at a time; have the room predict, then run):
print(True and not False)
- Trace: evaluate
not Falsefirst (notbinds tightest) →True. NowTrue and True→True. - Predicted:
True. Run it. Actual output (run-verified):
True
Worked trace #2 — or saves the day even when one side is false:
print(3 > 2 or 1 > 5)
- Trace:
3 > 2isTrue;1 > 5isFalse.True or False→True. - Output (run-verified):
True
"or only needs ONE true side. The second comparison being false doesn't matter."
Precedence — the rule that trips everyone (not → and → or): just like * before + in arithmetic, logical operators have an order: not first, then and, then or.
print(True or False and False)
- Trace:
andbeforeor, soFalse and False→Falsefirst, thenTrue or False→True. - Output (run-verified):
True
"If you read it left-to-right you'd compute True or False → True, then True and False → False — the WRONG answer. Precedence makes it True. When in doubt, add parentheses to say exactly what you mean — and run it."
Segment 4 — if / elif / else: Which Branch Runs? (23 min) · Session 1 closes (~75)
Set it up: "Now we use a Boolean to actually control the program. The if statement runs a block of code only when its condition is True."
The shape (put it on a slide): the condition ends with a colon, and the code that runs is indented underneath.
score = 72
if score >= 60:
print("Pass")
else:
print("Fail")
- Trace:
score >= 60is72 >= 60→True, so theifblock runs. - Output (run-verified):
Pass
"The indentation is not decoration — it tells Python which lines belong to the branch. Same four-space rule we'll use all term."
elif for more than two choices — the code-along (build a ticket-price program live, line by line):
age = 12
if age < 5:
print("Free")
elif age < 18:
print("Child: $8")
elif age < 65:
print("Adult: $12")
else:
print("Senior: $9")
- Trace which branch runs for
age = 12: check12 < 5?False. Check12 < 18?True→ run that branch and skip the rest. - Output (run-verified):
Child: $8
The load-bearing idea — Python takes the FIRST true branch and stops. Run the same program with different ages (change one line, re-run) and have the room predict each:
age |
Branch that runs | Output (run-verified) |
|---|---|---|
3 |
age < 5 |
Free |
12 |
age < 18 |
Child: $8 |
40 |
age < 65 |
Adult: $12 |
67 |
else |
Senior: $9 |
"Only ONE branch ever runs. Once a condition is true, Python executes that block and jumps past every elif and the else."
Worked "which branch runs" trace (reveal then run):
x = 7
if x > 10:
print("big")
elif x > 5:
print("medium")
else:
print("small")
- Trace:
7 > 10?False.7 > 5?True→medium, skipelse. - Output (run-verified):
medium
Quick interaction (rapid-fire, ~4 min): put three tiny if/elif/else programs on a slide with different input values; for each, students predict the branch + output solo (20 sec), then you run it.
Segment 5 — The Famous Bug: = vs == (20 min) · Session 2 opens
Hook back in: "Last session you wrote code that decides. Today you'll write the most common beginner mistake in the entire language on purpose — because once you've seen it, you'll never lose an hour to it."
Plain language first. Python uses two different things that look almost identical:
- = (single) is assignment — it stores a value: x = 5 puts 5 into x.
- == (double) is comparison — it asks a question: x == 5 evaluates to True or False.
A condition needs a question, so it needs ==. Put a single = in a condition and Python refuses.
Live demo #1 — the bug (put it on a slide exactly as is):
x = 5
if x = 5:
print("yes")
Run it. Python won't even start (run-verified):
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
"Read the last line — Python is literally telling you the fix: 'Maybe you meant ==.' A single = is assignment, which isn't allowed in a condition, so it's a SyntaxError — Python catches it before running a single line."
Live demo #2 — the fix, then run to confirm:
x = 5
if x == 5:
print("yes")
Output (run-verified):
yes
"== asks 'is x equal to 5?' → True, so the branch runs. One extra = changes a broken program into a working one."
Land the distinction (put it on a slide):
- = = store a value (temperature = 70). Lives on its own line, not in a condition.
- == = ask "are these equal?" (if temperature == 70:). Lives inside conditions.
- Memory hook: = puts a value IN; == ASKS a question.
Misconception + cure:
- ❌ "if x = 5: checks whether x is 5."
✅ Cure: no — = tries to assign, which Python forbids inside a condition, so it's a SyntaxError. Comparison needs ==. Read the error: Python even suggests ==.
Segment 6 — Spot & Fix the Bug: elif Order (18 min)
Set it up: "Here's a program with no syntax error at all — it runs perfectly — but it gives the wrong answer. This is a logic bug, the sneakier kind. Let's debug it together."
The buggy program (put it on a slide exactly as is): a grade classifier whose branches are in the wrong order.
score = 95
if score >= 60:
print("D or better")
elif score >= 90:
print("A")
else:
print("F")
Debug it out loud:
1. Predict: a 95 should obviously print A. Run it. Output (run-verified):
D or better
- "Wait — 95 is an A! Why did it say 'D or better'?" Read the logic: Python takes the first true branch.
95 >= 60isTrue, so it runs that branch and never checksscore >= 90. TheelifforAis unreachable for any score ≥ 60. - The bug: the conditions are ordered least-specific first. The broad net (
>= 60) catches everything before the specific test (>= 90) gets a turn. - The fix — order from most specific to least (highest threshold first), then run to confirm:
score = 95
if score >= 90:
print("A")
elif score >= 60:
print("D or better")
else:
print("F")
Output (run-verified):
A
Land the key idea: branch order is a correctness bug, not a syntax error. The program ran both times — Python never complained — but only the second one is right. With an if/elif chain that uses >= thresholds, put the biggest threshold first.
A second quick one (let the room solve it): ask which branch runs in the fixed program for score = 60 — trace it: 60 >= 90? False. 60 >= 60? True → D or better (run-verified). The boundary lands in the second branch because >= includes equality.
Segment 7 — Misconceptions Round-Up + Quick Interaction (20 min)
Name the misconceptions out loud, then cure each:
- ❌ "
=and==are interchangeable."
✅ Cure:=stores (x = 5);==asks (x == 5). A single=in a condition is aSyntaxError. The hook: value IN vs. ASK a question. - ❌ "
andandorare evaluated left to right."
✅ Cure: precedence isnot→and→or.True or False and FalseisTrue(theandruns first). When unsure, parenthesize and run it. - ❌ "The order of my
elifs doesn't matter."
✅ Cure: it matters a lot. Python takes the first true branch and stops; a broad condition placed first hides the specific ones. Order most-specific first. - ❌ "
not (3 > 2)isTrue."
✅ Cure:3 > 2isTrue, andnot TrueisFalse. Run it:print(not (3 > 2))→False. - ❌ "
0and''are just numbers/text, not Booleans."
✅ Cure: in a condition Python treats some values as falsy —0,0.0,""(empty string), and an empty list are all treated asFalse; most other values are truthy. (We'll lean on this lightly today; it returns with loops.) Run:print(bool(0))→False,print(bool(""))→False,print(bool("hi"))→True.
Interaction — Predict-then-Run (rapid-fire, ~8 min): put four expressions on a slide; students predict each output solo (30 sec), compare with a neighbor (1 min), then you run all four. Suggested with run-verified outputs:
| Expression | Output (run-verified) |
|---|---|
print(not True or True) |
True |
print(5 > 3 and 2 > 4) |
False |
print(10 == 10 or 5 < 1) |
True |
print(not (3 > 2)) |
False |
Tally how many the room got right — celebrate the misses as "this is exactly why we run code."
Segment 8 — Technology Workflow + AI-Critique, Callback & Hand-off (17 min) · Session 2 closes (~75)
Technology workflow — the everyday loop for Booleans:
1. Open the free online Python environment (link in the readings). Type the expression inside print(...).
2. Press Run. Read the True or False.
3. To watch an if/elif/else decide, paste it into Python Tutor and step forward — you'll literally see the arrow check each condition and jump to the branch that runs.
4. Unsure about precedence? Add parentheses to force the order you want, run both versions, compare.
AI-critique moment (students verify, not consume):
Paste this to an approved chatbot: "What does this Python program print?
print(True or False and False)— and which branch runs in this code, and what does it print?score = 60thenif score > 60: print('above') else: print('at or below')."
Then check its work by running both yourself. Chatbots routinely mis-rankandandor(they'll read left-to-right and sayFalsefor the first one — the correct answer isTrue), and they slip on boundary values (with>, a score of exactly60is not "above" — it printsat or below; an AI may say "above"). Your job all semester: the tool drafts, you run it and judge. This is exactly how the weekly Lecture Tutorial and Coding Lab work — you catch the model, not trust it.
Callback + tease:
- Callback: "Today: the bool type, the comparison and logical operators, truth tables and their precedence, and if/elif/else to pick a branch — plus the =-vs-== trap and why elif order matters."
- Tease next week: "Right now an if runs its block once. Next week we make code repeat — the while loop runs a block over and over as long as a condition stays true. We'll meet counters, accumulators, and the dreaded infinite loop (and how to stop it)."
Hand-off (the week's graded work):
- Lecture Tutorial 4 (AI tutor, share-link submission) — Booleans, truth tables, if/elif/else.
- Quiz 4 and Discussion 4 ("When Code Decides About People") and Assignment 4 ("Programs That Decide").
- Coding Lab 4 — "Decisions, Decisions" — write branching code, fill a predict-then-run truth table, and fix the =-vs-== bug.
Instructor FAQ — Common Stumbles
| Student says / does | Quick cure |
|---|---|
Writes if x = 5:. |
Single = is assignment, not allowed in a condition → SyntaxError: ... Maybe you meant '=='. Use ==. |
Thinks True or False and False is False. |
Precedence: and before or. False and False → False, then True or False → True. Run it. |
| All scores land in the first branch. | The first elif/if condition is too broad (e.g. >= 60 before >= 90). Order most-specific first. |
| Surprised a boundary value (e.g. exactly 60) falls where it does. | >=/<= include the boundary; >/< exclude it. Pick deliberately, then run the boundary. |
Forgets the colon: if x == 5 (no :). |
Every if/elif/else header ends with a colon, and the body is indented underneath. Missing colon → SyntaxError. |
Writes True or False in quotes. |
"True" is a string (always truthy); True is the Boolean. No quotes for Booleans. |
| Expects more than one branch to run. | Only the first true branch runs; the rest are skipped. Want several checks? Use separate ifs. |
| "I'll just reason it out instead of running it." | Reasoning is where precedence and boundary mistakes hide. The loop is edit → run → read → fix. Always run the Boolean. |
Scope flag
This outline stays within Objective 3 (the bool type; comparison and logical operators; truth tables and precedence; if/elif/else; which branch runs; the =-vs-== and elif-order bugs). We use only this week's constructs plus Weeks 1–3 (print, variables, int/float/str, simple arithmetic, comparisons) — for example, a single-input classifier, not loops or functions. Loops (while, for) are Weeks 5–6 and only previewed here; functions are Week 7. Truthiness/falsiness is touched lightly and returns with loops. Python and its error names (SyntaxError) are referenced factually; the instructor and institution remain fictional. Every output shown was produced by running the code.
~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com