Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Think of a bug that you met while working through this book, or write one on purpose. Write the five steps for it: how you reproduced it, where you located it, the explanation in one sentence, the one change that you made, and the test that you keep.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. There is no one right answer, so here is an example, to show the shape of a good one.
running_total([3, 1, 4, 1, 5]) gave [3, 4, 8, 9]. A list of two items, [1, 2], gave [1]: the smallest failing input.print of i inside the loop showed that i stopped one item early.range(len(numbers) - 1), so the last item is never added."len(numbers) - 1 to len(numbers).[1, 2] becomes a new test: assert running_total([1, 2]) == [1, 3].Check. A good answer has all five steps, explains the cause before the fix, and ends with a test that stays.
Answer: Your own bug, in the five steps.
Log in to join the discussion.
Loading…