Bug hunt: fix code you did not write

PremiumAdvanced25 min3 exercises

Most code you will ever fix was written by someone else, often a past version of you. It has no comments that say "the bug is here". This lesson is three programs that are broken on purpose, in ways that real programs break.

A process that works on all of them:

Some bugs crash with a traceback. The ones in this lesson do not: they run happily and give the wrong answer, which is why they survive. One of them is a classic Python trap that catches experienced programmers too. Read the example, then go hunting.

The rest of this lesson is Premium

Three broken Python programs to repair: an off-by-one loop, the shared default list, and a "find the biggest" that fails on negative numbers.

Module
Python Advanced: Read tracebacks, handle errors on purpose, build your own types, then hunt bugs in code you did not write.
Challenges
  • The countdown that stops early
  • The list that remembers
  • Nobody wins

First challenge: The countdown that stops early

count_down(3) should print 3, 2 and 1 on their own lines, then Go!. It prints one number too few. Fix the bug without adding a separate print(1).

£7.99 a month, or £59 a year

Premium opens every Core and Advanced lesson in all four tracks, with the editor, checker and hints, plus the bigger projects. Cancel any time.

See Premium

Or keep going for free: Python Foundations and the playground are free for good.