Skip to content

Read the error

Read · 1 of 3

Read a traceback bottom-up

The last line says what went wrong (TypeError, IndexError …). The line just above it says where: the file and line number. Everything higher up is how the program got there.

Fix the cause, not the symptom: an IndexError on line 5 usually means a loop on line 4 went one step too far.

1Traceback (most recent call last):
2 File "main.py", line 5, in <module>
3 total += nums[i]
4IndexError: list index out of range
Read this lesson as text

Python tells you what went wrong and where. Read it from the bottom.

Read a traceback bottom-up

The last line says what went wrong (TypeError, IndexError …). The line just above it says where: the file and line number. Everything higher up is how the program got there.

Fix the cause, not the symptom: an IndexError on line 5 usually means a loop on line 4 went one step too far.

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    total += nums[i]
IndexError: list index out of range

Exercise: Fix the crash

This should print a sentence like In 5 years Asha will be 25. Run it, read the error, and fix it.

Exercise: Fix the other crash

This should print the total of n numbers.