Check your understanding of the previous reading: reading tracebacks and recognizing common error types.

Question 1

According to the following error message, what line of code did the error occur on?

Traceback (most recent call last):
  File "my_code.py", line 32, in <module>
    45 + "NameError"
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Show explanation

The traceback line File "my_code.py", line 32, in <module> names both the file and the line number: line 32.

Question 2

According to the following error message, what type of error occurred?

Traceback (most recent call last):
  File "my_code.py", line 32, in <module>
    45 + "NameError"
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Select one answer, then check.

  • Correct. The last line of the traceback always names the error type: TypeError: unsupported operand type(s) for +: 'int' and 'str'.
  • Not quite. "NameError" here is just a string being added to 45 — it's not an actual error. The real error type is named on the last line.
  • Not quite. Nothing here breaks Python's grammar; the code is valid, it just fails when run.
  • Not quite. A traceback like this one is only shown when an error did occur.
  • Not quite. The error type is always named on the last line of the traceback.

Question 3

When your program has an error, the first thing you should do is:

Select one answer, then check.

  • Correct. Read and think about what the message is telling you before anything else — it often already points at the mistake.
  • Not the first step. Asking for help is useful, but read the message yourself first — it often already answers your question.
  • Understandable, but it won't fix the bug! Reading the error message will.
  • Not the first step. Debugging comes after you understand what the error message is telling you.

Question 4

Match each error type with its description.
You have referenced a variable that does not exist.
You have used an operator with incorrect types.
You have a mistake with your code's grammar or punctuation.
This is not a common type of error.