Reading Tracebacks

When an operation fails, Python raises an exception. This is Python's way of reporting an error. It then prints a traceback, a report that shows where the error happened. The last line gives the type of the exception and describes what went wrong.

values = [10, 20]
print(values[2])

Error:

Traceback (most recent call last):
  File "/box/main.py", line 2, in <module>
    print(values[2])
          ~~~~~~^^^
IndexError: list index out of range

Start reading at the bottom. IndexError means the code used a list position that does not exist. This list only has positions 0 and 1. The File line above it points to line 2, and the marks under the code point at values[2].

Tracebacks through a function

def first_word(text):
    words = text.split()
    return words[0]

print(first_word("hello there"))
print(first_word(""))

Output:

hello
Traceback (most recent call last):
  File "/box/main.py", line 6, in <module>
    print(first_word(""))
          ^^^^^^^^^^^^^^
  File "/box/main.py", line 3, in first_word
    return words[0]
           ~~~~~^^^
IndexError: list index out of range

"Most recent call last" means the entries are listed in the order the calls happened. The place that actually failed is at the bottom. Here, line 6 called first_word, and then line 3 inside the function failed.

The first call still printed hello before the crash, because Python runs every line up to the one that fails. The second call failed because an empty string splits into an empty list, so there is no words[0].

Now read the traceback in the question and find what caused it.