Open Source

BugLab

Not another LeetCode.

Most platforms ask: can you write it? Real work asks: why is this broken?

BugLab builds code-reading and debugging skills — one broken function at a time. Especially relevant as AI tools write more of the code we all maintain.

20
Exercises
8
Easy
8
Medium
4
Hard
20 exercisesSearch ↗
001-off-by-oneeasy

Off By One

The function sum_list should return the sum of all elements in a list. Something is wrong — it seems to miss the last element. Find the bug and fix it. Don't use sum() built-in — you must iterate manually.

loopsindexingclassic
4t
002-silent-returneasy

The Silent Return

functionsscopereturn
4t
003-wrong-conditionmedium

Is It Prime?

mathloopsconditions
8t
004-mutable-defaultmedium

The Haunted List

functionsdefaultsgotcha
4t
005-int-divisionmedium

One Too Many

mathloopscounters
4t
006-closure-traphard

Closure Trap

The function make_multipliers(n) should return a list of n functions, where the i-th function multiplies its argument by i. So make_multipliers(4)[2](5) should return 10 (2 × 5). But every single function in the list behaves identically — they all multiply by the same number. This is one of Python's most infamous gotchas. The code looks right. But it isn't.

closuresfunctionsscope
4t
007-shallow-copyhard

Vanishing Elements

listsiterationmutation
5t
008-generator-exhaustionhard

Exhausted

generatorsiteratorsgotcha
4t
009-identity-crisismedium

Identity Crisis

comparisonidentityequality
4t
010-float-precisionmedium

Almost Equal

floatsprecisioncomparison
4t
011-sort-returns-noneeasy

Sorted by Nothing

The function get_median(numbers) should return the median value of a list of numbers. For odd-length lists, the median is the middle element; for even-length lists, it is the average of the two middle elements. The function crashes immediately on any input with a TypeError. Can you find the single-word fix that makes it work?

listssortingmethodsgotcha
4t
012-missing-returnmedium

The Lost Return

recursioncontrol-flowfunctions
4t
013-zero-producteasy

Zero Product

loopsaccumulatormath
4t
014-operator-precedenceeasy

Wrong by Design

operatorsprecedencemath
4t
015-string-immutableeasy

Read-Only

stringsimmutabilitytypes
4t
016-dict-key-errormedium

Missing Key

The function word_frequency(words) should take a list of words and return a dictionary mapping each word to how many times it appears. It crashes on the very first word every single time. The error happens on a line that looks perfectly logical. Why does Python refuse to increment something that doesn't exist yet?

dictsKeyErrormethods
4t
017-shared-listhard

The Shared Row

listsreferencesmutation
4t
018-enumerate-starteasy

Wrong Rank

loopsenumerateoff-by-one
4t
019-truthiness-trapeasy

Misleading Truth

booleanstruthinesscomparison
4t
020-args-unpackingmedium

The Ignored Stars

functionsargsunpacking
4t