Step zero: make the bug happen on demand
You cannot run experiments on a bug you cannot trigger. So debugging always starts with a reproduction: a snippet that makes the failure happen every time. If you have unit 1's habits, that repro is simply a failing test.
Then minimize it. A bug report says median misbehaves on a big messy list, but big inputs hide causes. Shrink the input while the failure persists: cut the list in half, try each half (the halving idea returns in unit 9), keep whichever still fails, repeat. When you cannot shrink further, the remaining input usually names the bug: if median([1, 2]) fails and median([1, 2, 3]) works, the words "even length" are already in your hypothesis.
Code exercise · python
Run this minimization session. median is suspected wrong on the 8-item list (a sorted [1,2,4,4,6,7,8,9] should give 5.0). Watch the input shrink while the wrongness survives, down to a 2-item repro.
Reading the minimal repro
median([1, 2]) returns 2, but the median of 1 and 2 is 1.5. With two elements the bug is naked: len(nums) // 2 is 1, and picking index 1 is only correct when the length is odd. For even lengths the median is the average of the two middle elements, indexes n//2 - 1 and n//2.
Notice the loop from lesson 7-1 just happened: observe (6 instead of 5.0), hypothesize (even-length indexing), predict ([1, 2] should fail), experiment (it does), conclude. Now you fix it, and lesson 4-3's rule says the minimal repro becomes a permanent regression test.
Code exercise · python
Your turn: fix median for even-length lists. Odd lengths keep the middle element, even lengths return the average of the two middles. The tests, including the minimal repro, are already written.
Code exercise · python
Minimization works on any input, not just lists. count_words reports 5 words for a 4-word sentence. Run the shrinking session: each print keeps only a piece where the wrongness survives, until a 4-character repro remains. Read the minimal repro and say the bug out loud before peeking at the hints.