Week 2 — Lecture Outline · Variables, Data Types & Expressions
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective covered: Objective 2 — Use variables, the core data types (int, float, str, bool), and expressions to compute and store values; trace and debug what they produce — including operator precedence, / vs // vs %, and type conversion.
SLOs touched: A (write and run a correct program with variables) · B (trace expressions and predict output; find and fix a type/assignment defect)
Meeting pattern: 2 studio sessions × 75 min = 150 min. Segment minutes below total ~150; scale to your own pattern.
Every code output, traced value, 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. (This week's headline:
10 / 2really does print5.0.)
Week at a Glance
| The week's big question | "How does a program remember a value, and what exactly happens when it does math with it?" |
| By the end of the week, students can… | (1) store and reuse values in variables with = (assignment, not comparison); (2) name the four core types — int, float, str, bool — and check any value with type(); (3) evaluate expressions with operator precedence and predict / (always a float), // (floor), and % (remainder); (4) convert types with int()/float()/str() and fix the "5" + 3 TypeError. |
| Key vocabulary | variable, assignment (=), value, data type, int, float, str (string), bool (Boolean), type(), expression, operator, operator precedence, true division (/), floor division (//), modulo / remainder (%), exponent (**), type conversion / casting, int(), float(), str(), TypeError, NameError, reassignment |
| Materials | slides (Deck 2), 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. |
Segment 1 — Hook & Callback (8 min) · Session 1 opens
Callback first. "Last week your programs could only say fixed things — print("Hello"). If you wanted to greet a different name, you rewrote the code. Today we fix that: we give the program a memory."
Hook (do it live). Put a tiny problem on the board: "A video is 200 seconds long. How many whole minutes and leftover seconds is that?" Ask the room. Someone says "3 minutes and 20 seconds." "Right — and by the end of today you'll have written a program that figures that out for any number of seconds, using two operators you've never seen: // and %."
Why it matters line (memory hook): "A variable is a named box. = means put this value in the box — not is it equal?."
Segment 2 — Variables & the Four Core Types (22 min)
Plain language first. A variable is a named box that holds a value. You put a value in the box with the assignment operator =, and from then on the name stands for that value.
Code-along (everyone types each line and runs it):
score = 10
print(score)
Output:
10
"score = 10 puts 10 in a box named score. print(score) shows what's in the box. Read = left-to-right as 'gets': score gets 10."
Reassignment — the box can change:
score = 10
score = 25
print(score)
Output:
25
"The second line replaces what's in the box. A variable holds one value at a time — the most recent one."
The four core types (type each into the editor with type()):
print(type(20))
print(type(5.5))
print(type("Sam"))
print(type(True))
Output (run-verified):
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
Name them as they appear:
- int — a whole number: 20, -3, 0.
- float — a number with a decimal point: 5.5, 3.0, -1.25.
- str — text in quotes: "Sam", "hello".
- bool — a truth value: True or False (capital T/F, no quotes).
"type() is a tool that tells you what kind of value you have. We'll lean on it all week — when something behaves oddly, the first question is 'what type is this, actually?'"
Segment 3 — Expressions & Operator Precedence (the code-along) (22 min)
Plain language first. An expression is a calculation Python works out to a single value. Python follows operator precedence — the same order-of-operations idea from math: ** first, then * / // %, then + - — not strictly left to right.
Code-along, build a small calculator (everyone types each line and runs it):
bill = 50
tip = bill * 0.20
total = bill + tip
print(total)
Output (run-verified):
60.0
"We stored the bill, computed a 20% tip into its own box, added them, and printed. Notice the answer is 60.0 — a float — because we multiplied by 0.20. The moment a float enters the math, the result is a float."
Precedence, shown by running it:
print(2 + 3 * 4)
Output:
14
"* before +: 3 * 4 = 12, then 2 + 12 = 14 — not 20. Same trap as last week, now with the rule named: precedence."
print((2 + 3) * 4)
Output:
20
"Parentheses force the addition first. When in doubt, add parentheses — they make your intent explicit and override precedence."
print(2 ** 3 + 1)
Output:
9
"** is exponent — 2 ** 3 = 8 — and it happens before the +, so 8 + 1 = 9. Power binds tightest of all."
Segment 4 — / vs // vs %: the Division Surprise (20 min) · Session 1 closes (~75)
Set it up: "Here's the single most surprising thing in Week 2. Predict each before we run it."
Worked trace — / always makes a float (reveal one at a time; have the room predict, then run):
print(10 / 2)
- Predicted by most of the room:
5. Run it. Actual output (run-verified):
5.0
"Surprise. True division / ALWAYS returns a float in Python — even when it divides evenly. 10 / 2 is 5.0, not 5. This is the #1 thing chatbots get wrong this week, so burn it in: slash makes a decimal."
print(7 / 2)
Output:
3.5
Floor division // — divide and throw away the decimal:
print(7 // 2)
Output (run-verified):
3
"// is floor division: it divides and keeps only the whole-number part (it floors the result). 7 // 2 is 3, not 3.5."
Modulo % — the remainder:
print(7 % 2)
Output (run-verified):
1
"% is modulo: the remainder after division. 7 divided by 2 is 3 with 1 left over, so 7 % 2 is 1. (% is how you test even/odd, wrap a clock, or split leftovers.)"
Now the hook from Segment 1 pays off — the seconds → minutes program:
total_seconds = 200
minutes = total_seconds // 60
seconds = total_seconds % 60
print(minutes)
print(seconds)
Output (run-verified):
3
20
"// gives the whole minutes (3), % gives the leftover seconds (20). Together, // and % split a number into a quotient and a remainder. That's the program I promised at the start of class."
Quick interaction (rapid-fire, ~5 min): put four on a slide; students predict solo (20 sec each), then you run them. Suggested with run-verified outputs: print(8 / 4) → 2.0; print(10 // 3) → 3; print(10 % 3) → 1; print(2 ** 3) → 8.
Segment 5 — Types Collide: int(), float(), str() (22 min) · Session 2 opens
Hook back in: "Yesterday a value's type was just trivia. Today it bites — and you'll learn to fix it."
Plain language first. Sometimes a value is the wrong type for what you want to do, so you convert it with int(), float(), or str(). Converting is also called casting.
Live demo #1 — the classic crash:
print("5" + 3)
Run it. Python stops with (run-verified):
TypeError: can only concatenate str (not "int") to str
""5" is a string (it's in quotes); 3 is an int. Python won't add text to a number — + would mean 'join' for the string but 'add' for the number, and it refuses to guess. That's a TypeError: the right operation, the wrong types."
The fix — convert the string to an int first:
print(int("5") + 3)
Output (run-verified):
8
"int("5") turns the string "5" into the number 5; now 5 + 3 is 8. The lesson: when a TypeError mentions str and int, a value is the wrong type — convert it."
The other direction — put a number into a message:
total = 21.4
print("Your total is " + str(total))
Output (run-verified):
Your total is 21.4
"To glue a number onto a string, convert the number with str() first. (Next week's f-strings will make this prettier — today, str() is the tool.)"
One more conversion to show (run it):
print(int(3.9))
Output:
3
"int() on a float truncates — it drops the decimal part, it does NOT round. int(3.9) is 3, not 4. Worth knowing before it surprises you."
Segment 6 — Spot & Fix the Bug (the debugging demo) (16 min)
Set it up: "Here's a program that's supposed to print a total but crashes. Let's debug it — find the bug, predict the fix, run to confirm."
The buggy program (put it on a slide exactly as is):
quantity = "3"
price = 4
total = quantity * price
print(total)
Debug it out loud:
1. Run it. It doesn't crash — but it prints something weird (run-verified): 3333.
2. "We expected 12 (three items at $4). Instead we got 3333. Why? quantity is the string "3" — it's in quotes. And "3" * 4 doesn't multiply — it repeats the text four times, giving "3333"." (Run it live so the surprise is real, then diagnose.)
3. The bug: quantity was stored as a string, not a number, so * repeated the text instead of multiplying.
4. The fix, then run to confirm:
quantity = int("3")
price = 4
total = quantity * price
print(total)
Output (run-verified):
12
Land the key idea: "The operator wasn't wrong — the type was. Most 'weird output' bugs this week are type bugs. When math acts strange, ask type() what you're really working with."
A second quick bug (let the room solve it):
print(score)
score = 10
Run it → run-verified NameError: name 'score' is not defined. "You used the box before you put anything in it. Python reads top to bottom; score doesn't exist yet on line 1. The fix: assign before you use — swap the two lines."
Segment 7 — Misconceptions Round-Up + Quick Interaction (20 min)
Name the misconceptions out loud, then cure each:
- ❌ "
10 / 2is5."
✅ Cure:/always returns a float —10 / 2is5.0. Use//if you want the whole number5. When unsure, run it. - ❌ "
//rounds."
✅ Cure://floors (drops the fraction).7 // 2is3;int(3.9)is3too — truncation, not rounding. - ❌ "
=and==are the same."
✅ Cure:=stores a value in a box (assignment);==compares two values (we meet it in Week 4).score = 10is an action; it is not a question. - ❌ "
"5" + 3adds to8."
✅ Cure: it crashes with aTypeError— you can't add a string and an int. Convert first:int("5") + 3is8. - ❌ "Capital, lowercase — whatever;
Scoreandscoreare the same box."
✅ Cure: Python is case-sensitive.Scoreandscoreare two different variables. Pick a name and spell it the same way every time.
Interaction — Predict-then-Run (rapid-fire, ~8 min): put four programs 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: print(7 // 2) → 3; print(7 % 2) → 1; print(10 / 2) → 5.0; print(type("hi")) → <class 'str'>. Tally how many the room got right — celebrate the misses on the division ones as "this is exactly why we run code."
Segment 8 — Technology Workflow + AI-Critique, Callback & Hand-off (18 min) · Session 2 closes (~75)
Technology workflow — the everyday loop, with a type twist:
1. Open the free online Python environment (link in the readings). Type your code.
2. Press Run. Read the output — or the error.
3. If it's a TypeError, the message names the types involved (str, int). That's your clue: convert a value with int(), float(), or str().
4. To watch a variable change, paste the code into Python Tutor and step forward — you'll literally see the box's value update on reassignment.
AI-critique moment (students verify, not consume):
Paste this to an approved chatbot: "What does this Python program print?
print(10 / 2)— and alsoprint(7 // 2)andprint(7 % 2)."
Then check its work by running all three yourself. Chatbots routinely say10 / 2is5(dropping the.0) — Python prints5.0. Your job all semester: the tool drafts, you run it and judge. The division surprise is the perfect place to catch the model this week.
Callback + tease:
- Callback: "Today: variables store values; type() names them; precedence and / vs // vs % govern the math; and int()/float()/str() convert between types so "5" + 3 becomes int("5") + 3."
- Tease next week: "Right now we put values into variables ourselves. Next week the program asks the user for a value with input() — and since input() always hands back a string, this week's type-conversion habit becomes essential. We'll also dig into strings: indexing, slicing, and f-strings for clean output."
Hand-off (the week's graded work):
- Lecture Tutorial 2 (AI tutor, share-link submission) — variables, the four types, type(), precedence, / vs // vs %, and type conversion.
- Quiz 2 and Discussion 2 ("Naming & Readability") and Assignment 2 ("Compute, Convert, Fix").
- Coding Lab 2 — "Boxes, Math & a Sneaky Decimal" — write with variables, build the predict-then-run expression table, fix a type/assignment bug, and visualize a swap in Python Tutor.
Instructor FAQ — Common Stumbles
| Student says / does | Quick cure |
|---|---|
"Why does 10 / 2 print 5.0? I wanted 5." |
/ is true division and always returns a float. For a whole number, use //: 10 // 2 is 5. |
Confuses // with rounding. |
// floors (drops the fraction). 7 // 2 is 3; 9 // 2 is 4 only because 9/2 = 4.5 floors to 4. It never rounds up. |
""5" + 3 should be 8." |
It's a TypeError — can't add a str and an int. Convert: int("5") + 3 is 8. |
Writes score == 10 to store a value. |
= stores (assignment); == compares. To put 10 in the box, use a single =. |
| Uses a variable before assigning it. | NameError: name '...' is not defined — Python runs top to bottom; assign the variable before you use it. |
Thinks print(2 + 3 * 4) is 20. |
Precedence: * before + → 14. Add parentheses to force a different order. |
Math on a quoted number acts strangely ("3" * 4 → 3333). |
A quoted value is a string. * repeats text; it doesn't multiply. Convert with int() first. |
Surprised int(3.9) is 3. |
int() on a float truncates (drops the decimal); it does not round. Use round() if you want rounding. |
"The chatbot said 10 / 2 is 5." |
It's wrong — run it. Python prints 5.0. This is the week's signature AI-critique catch. |
Scope flag
This outline stays within Objective 2 (variables; the four core types; expressions, precedence, / vs // vs %; type conversion). We use only print, variables, literals, arithmetic operators, type(), and int()/float()/str() — plus the two errors students will actually hit (TypeError, NameError). input() and f-strings are Week 3; Booleans/comparisons (==) are Week 4; conditionals, loops, and functions come later. Python and its type/error names (int, float, str, bool, TypeError, NameError) 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