Python from zero lesson plan
Beginner Python on a Raspberry Pi: print, variables, decisions, loops, lists, functions, dicts and strings, then a button with gpiozero and a working pedestrian crossing.
Objectives and materials
By the end, students can
- Make the Pi talk, remember and decide.
- Loops, lists, functions and dicts: the tools every program is made of.
- Read a button properly, with gpiozero.
- A pedestrian crossing built from everything in the course.
Materials for the whole unit
- Half breadboard
- LED x 2
- Motion sensor
- 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.
First words
Make the Pi talk, remember and decide.
| Lesson | Time | What students do |
|---|---|---|
| Print and variablesYour first Python on a Raspberry Pi: print() to talk, variables to remember, a little math, f-strings, the three types you meet first, and an LED switched on from code. | 45 min |
|
| Decisionsif, elif and else: comparisons, True and False, and, or and not, why indentation is part of the code, and a motion alarm that decides twice a second whether to light up. | 45 min |
|
Materials
- Half breadboard
- LED x 2
- Motion sensor
- Raspberry Pi 4 Model B
- Resistor x 2
Check for understanding
Each student finishes "Decisions" 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: "Indentation is the meaning".
Repeat and organize
Loops, lists, functions and dicts: the tools every program is made of.
| Lesson | Time | What students do |
|---|---|---|
| Loops and listsfor and range, lists you can index and grow, a list of real LEDs lit one after another, while loops that run forever, and break to stop one when the job is done. | 45 min |
|
| Functionsdef to name a few lines and run them by name, parameters and defaults, return to hand a value back, functions that choose a light, and why a value goes in and comes out instead of being shared. | 45 min |
|
| Dicts and stringsDictionaries that look a value up by its name, strings you can split, clean and change, and a little command line on the Pi: type "red on" and the red light obeys. | 45 min |
|
Materials
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Check for understanding
Each student finishes "Dicts and strings" 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: "A status command, in order".
Touch the world
Read a button properly, with gpiozero.
| Lesson | Time | What students do |
|---|---|---|
| Reading a button with gpiozeroA pushbutton on GPIO21: asking with is_pressed, why a pull-up keeps the pin from floating, waiting for a press, contact bounce, header pin numbers, timeouts, and callbacks that run when it happens. | 45 min |
|
Materials
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Check for understanding
Each student finishes "Reading a button with gpiozero" 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: "Callbacks: when it happens".
Boss project
A pedestrian crossing built from everything in the course.
| Lesson | Time | What students do |
|---|---|---|
| Project: traffic lightsThe boss project: a pedestrian crossing on the traffic light module and a button, built from everything in the course: a phase function, the sequence as a list, a loop waiting on the button, a counter and a flashing amber. | 45 min |
|
Materials
- Pushbutton
- Raspberry Pi 4 Model B
- Traffic light module
Check for understanding
Each student finishes "Project: traffic lights" 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: "What you built".
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.