Exercise 2: Fix This Chapter's average() Bug — Possible Solution ==================================================================== STEPS ------------------------------ 1. Enter this chapter's own buggy example: def average(numbers): total = 0 for n in numbers: total += n return total / len(numbers) - 1 # bug: the -1 shouldn't be here result = average([10, 20, 30]) print(result) 2. Set a breakpoint on the "return" line. 3. Press F5. Execution pauses right before that line runs. 4. Check the Variables panel: total = 60, numbers = [10, 20, 30] — both correct so far. 5. Hover over "total / len(numbers)" (just that portion of the expression, not the whole line) directly in the editor. A tooltip shows 20.0 — the mathematically correct average of [10, 20, 30]. 6. This confirms the bug is specifically the trailing "- 1" — the division itself is fine, but something is being subtracted afterward that shouldn't be there. 7. Stop the debug session, remove the "- 1" from the return line: return total / len(numbers) 8. Run the script again (with or without the debugger) — it now prints 20.0, the correct result. WHY THIS WORKS AS AN ANSWER ------------------------------ Hovering over the sub-expression total / len(numbers) rather than the whole return line reuses the chapter's own point that hovering shows "its value in a small tooltip, right where you're already looking" — isolating just that portion of the expression narrows down exactly which PART of the calculation is correct (the division) versus which part introduces the bug (the trailing subtraction), without needing to add any print statements or rewrite the function to test pieces of it in isolation. This exercise directly re-runs the chapter's own worked example end-to-end — confirming 19.0 was wrong, using the debugger to isolate that 20.0 (not 19.0) is what the division alone produces, and then applying that finding as the actual code fix, closing the loop from "there's a bug" to "here's the corrected function."