Walkthrough: Print-Debug an Off-by-One
例题: 用 print 调试 off-by-one
A function that runs fine but returns the wrong number. The hardest bug type — no exception, no traceback. Walk through finding it with print debugging.
The bug
sum_to_n(5) should return 15, but returns 10
Step 1 — Add print scaffolding
Python · runnable
Step 2 — Fix and verify
Python · runnable