The rules of the hunt
Four small programs, each crashing with a different bestiary entry. For each one, run the full lesson 7-1 loop:
- run it and read the traceback bottom-up (lesson 8-1)
- let the exception type narrow the hypothesis (lesson 8-2)
- change one thing and rerun
The expected output under each block tells you what the healthy program prints. No peeking at hints until the trace has told you its story.
Code exercise · python
Hunt 1. Crashes with a NameError. Read the message carefully, it quotes the name Python could not find. Fixed output: three converted temperatures.
Code exercise · python
Hunt 2. Crashes with an IndexError inside the comprehension. Remember indexes run from 0 to len-1. Fixed output: the last letter of each word.
Code exercise · python
Hunt 3. Crashes with a KeyError halfway through the order. The spec says items missing from inventory should print 0 instead of crashing. Fixed output: three lines.
Code exercise · python
Hunt 4. Crashes with a TypeError mentioning NoneType — the exact trap lesson 8-2's special note warned about. Fixed output: the four scores in ascending order.
Quiz
In hunt 1, the traceback pointed at the print line inside the loop, yet the fix was correcting a name. What does that illustrate?