
Bug hunt
Bug Hunt with Print
Every programmer writes bugs. Good programmers have a calm way to find them:
- Reproduce it: find a small input that gives a wrong answer.
- Print debugging: add temporary
print()lines to see what your variables really hold at each step:print("i =", i, "total =", total). - Rubber duck: explain the code line by line, out loud, to a rubber duck (or a patient friend). You'll often hear the bug as you say it!
- Fix, then remove your debug prints.
The bugs
The navigator's speed tools are giving strange answers:
average_speed([4, 6, 8]) -> 4.666... (should be 6.0)
slowest([4, 6, 8]) -> 0 (should be 4)
Assignment
Find and fix the bug in each function. Try un-commenting the debug
print first to watch what happens!
Find and fix the bug in each function. Try un-commenting the debug
print first to watch what happens!
main.py Python sleeping
Press Run to try your code, then Check to test it.