practicepython.in
python exercises
171 exercises

Reading broken code

Code that runs perfectly happily and gives the wrong answer. Professionals spend far more time reading and diagnosing than writing, and almost no tutorial practices it — so here the code is already written, and the job is working out why it is wrong.

8 exercisesdifficulty 2–4~165 min in total
The basket that adds up to almost rightdebug float equality, tolerance ~20 min The leaderboard where 9 beats 100debug sort keys, strings that look like numbers ~20 min 'int' object is not callabledebug shadowing a built-in, name lookup order ~18 min The basket that remembersdebug default arguments, when defaults are evaluated ~20 min The snippet that is short at one end and wrong at the otherdebug exclusive slice ends, negative indices wrap ~22 min The cleanup that crashes halfway throughdebug mutating while iterating, build rather than delete ~20 min The filter that misses every other onedebug iterating while modifying, how for walks a list ~20 min Three discount buttons, one discountdebug closures, late binding ~25 min