W WolfCode · CSC 141

Walkthrough: Print-Debug an Off-by-One

例题: 用 print 调试 off-by-one

≈ 8 min · python-debugging · Open in WolfCode

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