Source: https://mokxi.com/teachers/plans/python-from-zero
Updated: 2026-11-11

Lesson plan

# 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.

4 chapters, 7 lessons, about 5 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## 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.

Chapter 1. About 1 h 30 min

## First words

Make the Pi talk, remember and decide.

Lesson | Time | What students do

Print and variables Your 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

- Run your first program
- A variable is a name for a value
- Do math with a variable
- f-strings: values inside text
- Three types of value
- Switch on a real LED

Decisions if, 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

- Run it: one of two paths
- Send it the other way
- elif: more than two paths
- True, False, and, or, not
- Decide on a real sensor
- Indentation is the meaning

### 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".

Chapter 2. About 2 h 15 min

## Repeat and organize

Loops, lists, functions and dicts: the tools every program is made of.

Lesson | Time | What students do

Loops and lists for 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

- Run it: three laps
- Count from one
- A list holds many values
- A list of real LEDs
- while: keep going
- Stop with break

Functions def 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

- Run it: one name, three flashes
- A parameter with a default
- return hands a value back
- A function that picks a light
- Values go in and come out
- Why functions

Dicts and strings Dictionaries 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

- Run it: look up by name
- Take a string apart
- A dict of lights
- Type commands into the Pi
- A name that is not there
- A status command, in order

### 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".

Chapter 3. About 45 min

## Touch the world

Read a button properly, with gpiozero.

Lesson | Time | What students do

Reading a button with gpiozero A 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

- Run it and hold the button
- Why there is a pull-up
- Wait for a press
- Bounce, and header pin numbers
- Wait, but not forever
- Callbacks: when it happens

### 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".

Chapter 4. About 45 min

## Boss project

A pedestrian crossing built from everything in the course.

Lesson | Time | What students do

Project: traffic lights The 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

- Run it: green for the cars
- One function forevery phase
- The sequence is data
- Count the crossings
- Flash the amber
- What you built

### 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".

Your class

## 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.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
