Source: https://mokxi.com/learn/path/debugging-python
Updated: 2026-11-20

All paths

# Debugging Python

Find and fix real bugs in a deep sea probe's Python on a Raspberry Pi: tracebacks, print and logging, asserts, bisection, off-by-one errors and state bugs, then three broken scripts as the boss.

Raspberry Pi 4 Model B Free 7 lessons 5 h 4 chapters 2,076 XP Coding · Intermediate +150 XP

0 of 7 done

Start the course free Reading a traceback Lesson plan for teachers

What you will build

## 3 projects, built step by step

7 lessons in 4 chapters, about 5 hours on a simulated Raspberry Pi 4 Model B. Free, in your browser, every step checked by the simulator.

Chapter 1 project

### Print vs logging

The sonar contact lamp never lights. Find out why with print statements, fix it, then turn the prints into logging with levels, names and line numbers you can switch off without deleting a line.
Open it in the simulator

Chapter 2 project

### Bisecting a bug

The sonar puts the sea floor at 21,579 m. Find the broken stage by halving the pipeline, then use the same halving to find one bad ping in a thousand and the first bad firmware version in sixteen.
Open it in the simulator

Chapter 3 project

### State bugs

Bugs that live in remembered values: a toggle that crashes on its first press, a default list shared by every dive, a backup that empties itself, and a deepest-point record that leaks from one dive into the next.
Open it in the simulator

The map

## Chapter by chapter

Each lesson opens when the one before it is done, and each chapter ends in a project.

Chapter 1

## Read the clues

Tracebacks, prints and logs: make the program tell you what went wrong.

Open 205 XP

### Reading a traceback

The Nereus depth script crashes. Read a MicroPython traceback from the bottom up, fix a bad reading, a misspelled name and a missing key, and catch bad input without losing the traceback.

0 of 5 steps

Start What is in it

Project Locked 410 XP

### Print vs logging

The sonar contact lamp never lights. Find out why with print statements, fix it, then turn the prints into logging with levels, names and line numbers you can switch off without deleting a line.

0 of 5 steps

5 questions, graded as you go.

Chapter 2

## Set traps

Asserts that catch a bug where it starts, and halving that finds it anywhere.

Locked 205 XP

### Asserts

The ballast tank goes below empty without a word. Make the program check its own assumptions with assert, fix the bug the assert catches, and turn asserts into small tests that guard the fix.

0 of 5 steps

Project Locked 410 XP

### Bisecting a bug

The sonar puts the sea floor at 21,579 m. Find the broken stage by halving the pipeline, then use the same halving to find one bad ping in a thousand and the first bad firmware version in sixteen.

0 of 5 steps

5 questions, graded as you go.

Chapter 3

## The classics

Off by one and remembered state: the two bugs every program meets.

Locked 187 XP

### Off by one

The most common bug in programming, four ways: an index one past the end, a loop that skips the first reading, a zone boundary on the wrong side, and a fence post. Each found with the same checklist and lit on the traffic lights.

0 of 5 steps

Project Locked 410 XP

### State bugs

Bugs that live in remembered values: a toggle that crashes on its first press, a default list shared by every dive, a backup that empties itself, and a deepest-point record that leaks from one dive into the next.

0 of 5 steps

5 questions, graded as you go.

Chapter 4

## Boss

Three broken scripts, one hour to the dive.

Locked 249 XP

### Boss: three broken scripts

The boss: three of Nereus's scripts fail before a dive, a beacon that never flashes, a log summary that crashes on its first line and a mode button that dies on the third press. Find each bug with the right technique, fix it, and write the bug report.

0 of 7 steps

3 questions, graded as you go.

Syllabus

## Every lesson in the course

All 7 lessons, in order, each with what it covers. Any of them opens in the editor right away.

Chapter 1

### Read the clues

- Reading a traceback The Nereus depth script crashes. Read a MicroPython traceback from the bottom up, fix a bad reading, a misspelled name and a missing key, and catch bad input without losing the traceback.
- Print vs logging The sonar contact lamp never lights. Find out why with print statements, fix it, then turn the prints into logging with levels, names and line numbers you can switch off without deleting a line.

Chapter 2

### Set traps

- Asserts The ballast tank goes below empty without a word. Make the program check its own assumptions with assert, fix the bug the assert catches, and turn asserts into small tests that guard the fix.
- Bisecting a bug The sonar puts the sea floor at 21,579 m. Find the broken stage by halving the pipeline, then use the same halving to find one bad ping in a thousand and the first bad firmware version in sixteen.

Chapter 3

### The classics

- Off by one The most common bug in programming, four ways: an index one past the end, a loop that skips the first reading, a zone boundary on the wrong side, and a fence post. Each found with the same checklist and lit on the traffic lights.
- State bugs Bugs that live in remembered values: a toggle that crashes on its first press, a default list shared by every dive, a backup that empties itself, and a deepest-point record that leaks from one dive into the next.

Chapter 4

### Boss

- Boss: three broken scripts The boss: three of Nereus's scripts fail before a dive, a beacon that never flashes, a log summary that crashes on its first line and a mode button that dies on the third press. Find each bug with the right technique, fix it, and write the bug report.

Kits

## Build it on your bench too

Every lesson runs in the simulator with nothing to buy. When you want the real thing, these kits have the parts.

Have a kit already?

### Find your kit

Pick the starter kit you own and run every lesson in its manual with the same parts on the same pins.
See every kit

Questions

## About Debugging Python

Is Debugging Python free?

Yes. All 7 lessons of Debugging Python are free and run in your browser, with nothing to install and no parts to buy before you start.

Do I need a real Raspberry Pi 4 Model B?

No. Every lesson runs on a simulated Raspberry Pi 4 Model B with its parts on the canvas, and the simulator checks each step as you go. When you want to build it for real, the same wiring and code work on a real board.

How long does Debugging Python take?

About 5 hours: 7 lessons in 4 chapters, each one a few short steps. Your progress is kept, so you can stop after any lesson and pick up where you left off.

What will I build?

Each chapter ends in a project that puts it together: Print vs logging, Bisecting a bug and State bugs.

Where do I start?

With "Reading a traceback", and each lesson builds on the one before it. New to circuits? Electronics basics is the course that starts from zero.
