Source: https://mokxi.com/teachers/plans/coding-puzzles-python
Updated: 2026-11-19

Lesson plan

# Coding puzzles with Python lesson plan

Crack the classic programming puzzles as a space station crew, from FizzBuzz and primes to binary search, tic-tac-toe and calendar math, and finish with a Sudoku referee that lights up on the Pi.

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

- Remainders, rules as data, and the primes hiding in a signal.
- Palindromes from both ends, and the halving trick behind binary search.
- A board in a list of lists, a computer that blocks, and days counted from 1900.
- Every idea in one referee: the Sudoku checker.

### Materials for the whole unit

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

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 20 min

## Number puzzles

Remainders, rules as data, and the primes hiding in a signal.

Lesson | Time | What students do

FizzBuzz and friends The most famous warm-up puzzle in programming: find the bug in a first FizzBuzz, fix the order of the tests, count a hundred answers, turn the rules into data so a new rule is one line, meet the hailstone numbers, and play it on two LEDs. | 40 min

- Run it: find the bug
- Order matters
- Count a hundred
- Rules as data
- A friend: hailstones
- FizzBuzz in lights

Primes Decode a signal made of primes: test a number by trial division, stop at the square root, cross out multiples with the Sieve of Eratosthenes to find 1229 primes at once, hunt twin primes, split numbers into prime factors, and build a prime detector with two LEDs. | 40 min

- Run it: test every divisor
- Stop at the square root
- The sieve
- Twin primes
- Prime factors
- A prime detector

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Primes" 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 prime detector".

Chapter 2. About 1 h 20 min

## Words and search

Palindromes from both ends, and the halving trick behind binary search.

Lesson | Time | What students do

Palindromes Words that read the same both ways: reverse a string without the slice MicroPython lacks, clean phrases down to their letters, check from both ends with two pointers, find palindrome years and count palindrome numbers, find the longest one hidden in a string, and run a docking computer with two LEDs. | 40 min

- Run it: backwards and forwards
- Phrases
- Two pointers
- Palindrome numbers
- The longest one inside
- The docking computer

Guessing strategy Guess a secret number and discover binary search: play by halving the range, write a robot that halves for you, measure its worst case and average over every secret, see why a million numbers take only 20 guesses, and use the same idea to find the square root of 2. | 40 min

- Run it: a guessing game
- Halve it
- A robot player
- Worst case and average
- A million numbers
- Halving finds roots

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Guessing strategy" 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: "Halving finds roots".

Chapter 3. About 1 h 20 min

## Grids and dates

A board in a list of lists, a computer that blocks, and days counted from 1900.

Lesson | Time | What students do

Grids and tic-tac-toe Store a grid as a list of lists: draw it, read cells by row and column, list all 8 winning lines to find a winner, play two players over the Serial Monitor with every bad move answered, light the winner on the LEDs, and play a computer that wins when it can and blocks when it must. | 40 min

- Run it: a grid in a list
- Rows and columns
- Find the winner
- Two players
- Lights for the winner, and a draw
- A computer that blocks

Calendar math Date puzzles from mission control: fix a leap year rule that fails on 1900, count the day of the year, work out the weekday of the Moon landing by counting days from 1900, check your answer against datetime, and find the next Friday the 13th. | 40 min

- Run it: leap years
- Fix the rule
- Day of the year
- What day was the Moon landing?
- Check against datetime
- Friday the 13th

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Calendar math" 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: "Friday the 13th".

Chapter 4. About 50 min

## Boss

Every idea in one referee: the Sudoku checker.

Lesson | Time | What students do

Boss: a Sudoku checker The finale puzzle: check a Sudoku grid. Draw it with box lines, check rows, columns and 3 x 3 boxes with one shared test, report exactly which digit repeats where, check a half-solved puzzle with zeros for blanks and light the answer, then take typed moves and judge each one. | 50 min

- Run it: the grid
- One test for every group
- Columns
- Boxes, and the verdict
- Say exactly what is wrong
- A puzzle in progress
- Referee live moves

### Materials

- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2

### Check for understanding

Each student finishes "Boss: a Sudoku checker" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Referee live moves".

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.
