Thinking like a programmer lesson plan
The habits behind the code, right after Python from zero: break problems down, spot patterns, read flowcharts, plan in pseudocode, trace by hand and debug, then build a sorting robot that shows its work in lights.
Objectives and materials
By the end, students can
- Break a problem into parts and find what repeats.
- Flowcharts and pseudocode: the program drawn and written in words first.
- Be the computer with a trace table, then debug one bug at a time.
- Every habit in one build: a sorting robot on the traffic lights.
Materials for the whole unit
- Half breadboard
- LED x 2
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor x 2
- Traffic light module
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
See the shape
Break a problem into parts and find what repeats.
| Lesson | Time | What students do |
|---|---|---|
| Break it downDecomposition: take a launch that is one long list of instructions, split it into named parts, give the parts inputs so one piece does many jobs, let a part answer GO or NO GO, and light the answer on the Pi. | 40 min |
|
| Patterns and loopsSpot what repeats and what changes: turn hand-written lines into a loop, describe a rocket shape with a rule, find the pattern that adds 1 to 100 without adding, and store a beacon's blink pattern as data. | 40 min |
|
Materials
- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2
Check for understanding
Each student finishes "Patterns and loops" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A pattern as data".
Plan before code
Flowcharts and pseudocode: the program drawn and written in words first.
| Lesson | Time | What students do |
|---|---|---|
| Flowcharts to codeRead a flowchart and write the code it draws: boxes in a row become lines in order, a diamond becomes an if, an arrow back becomes a loop, and a wait for a person becomes a button. On a real traffic light module. | 40 min |
|
| Pseudocode firstPlan in plain words before you write Python: turn pseudocode into code line by line to find the hottest of a day's hull temperatures, then the average and the hot hours, check your work against Python's built-ins, and raise an alarm. | 50 min |
|
Materials
- Half breadboard
- LED x 2
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor x 2
- Traffic light module
Check for understanding
Each student finishes "Pseudocode first" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Raise the alarm".
Check the work
Be the computer with a trace table, then debug one bug at a time.
| Lesson | Time | What students do |
|---|---|---|
| Tracing by handBe the computer: fill in a trace table for a loop before running it, print the trace to check yourself, trace a while loop to its last turn, find a swap bug on paper, and follow values through nested function calls. | 40 min |
|
| Debug a recipeDebug like a programmer, one bug at a time: predict what a recipe program should print, compare it with what it does, and fix a scaling formula upside down, a loop that skips the last step, two steps in the wrong order, and an egg count that rounds the wrong way. | 40 min |
|
Materials
- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2
Check for understanding
Each student finishes "Debug a recipe" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Bug 4: half an egg".
Project
Every habit in one build: a sorting robot on the traffic lights.
| Lesson | Time | What students do |
|---|---|---|
| Project: a sorting robot on LEDsThe project: a robot that sorts cargo crates by weight. Draw the crates as bars, do one pass of neighbor swaps, repeat it into a full bubble sort, stop early when nothing moves, show every compare and swap on the traffic lights, and count the cost of the worst case. | 50 min |
|
Materials
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Check for understanding
Each student finishes "Project: a sorting robot on LEDs" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "The worst case".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.