Bug hunt

Bug Hunt with Print

Every programmer writes bugs. Good programmers have a calm way to find them:

  1. Reproduce it: find a small input that gives a wrong answer.
  2. Print debugging: add temporary print() lines to see what your variables really hold at each step: print("i =", i, "total =", total).
  3. 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!
  4. 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!