Reading a traceback
When Python crashes it prints a traceback. Read it from the bottom up:
- The last line names the error type and gives a message, like
KeyError: 'A03'. That's what went wrong. - The line above it shows the file, line number and code where it happened.
- Lines further up show who called that function, back to the start.
The error type points at the kind of bug. KeyError means a missing dict
key. TypeError means the wrong type, often None. IndexError means past
the end of a list.
Run the code. It crashes on purpose. Use the traceback to find the line, then fix it so the program prints the total. Then try the Debugging challenges, which are interview-style versions of this.