Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 10+ · Coding · Python
Reading error messages
Read thelast lineFind theline numberLook atthat lineChange onethingRun itagain
Every error has a plan.
The big ideaAn error message is a clue. Read the last line, find the line, fix it.

How it works

An error message is a clue from the computer. It says what happened and where. It is not a telling-off, and nothing is broken.

Read the last line first. It names the kind of problem.

Just above it is a line number, which says where the computer got stuck.

Look closely at that line, change one thing so you know what helped, and run it again.

The name says• NameError• SyntaxError• IndexError• IndentationError• TypeErrorIt means• cannot find a name• a piece missing or extra• no box with that number• not pushed in right• text and a number mixed
Five kinds of error and what they mean.

Example 1: A NameError

  1. Mina reads the last line: NameError, the name cont is not defined.
  2. The line number says line three, so she looks there.
  3. On line three she typed cont, but she meant count.
  4. She adds the missing letter, runs it again, and Bo waves.

Example 2: A SyntaxError

  1. Teo's for line is missing its colon.
  2. The last line says SyntaxError, and it says a colon was expected.
  3. Syntax is how a line is written, so a piece is missing.
  4. Teo adds the colon and runs it again.

Example 3: An IndexError

  1. Mina has a list of three snacks and asks for box three.
  2. The last line says IndexError: list index out of range.
  3. Boxes count from zero, so the boxes are 0, 1 and 2, and the last box is two.
  4. One small change to box two fixes it.

Example 4: The plan

  1. An error message pops up.
  2. Read the last line, find the line number, and look at that line.
  3. Change one thing, and run it again.
  4. It is fixed, or you get a new clue.

Words to know

error message
A clue from the computer about what happened and where.
line number
Says where the computer got stuck.
NameError
The computer cannot find a name, often a typo.
SyntaxError
A line is written with a piece missing or extra.
IndexError
A list has no box with that number.

Watch out

Try it

  1. Where do you read first in an error message?
  2. A list has three boxes and the code asks for box three. Which error is it?
  3. What does a NameError often mean?
  4. What should you do after you change one thing?
  5. A for line is missing its colon. Which error is it?
Answers: 1. The last line · 2. IndexError · 3. A typo in a name · 4. Run it again · 5. SyntaxError
Try at homeAsk a grown-up to write a short sentence with one tiny slip, like a missing letter or a missing full stop. Read it slowly, from the last word back to the first, to find the slip, just as a coder does with an error message.
For grown-upsWhen your child meets an error on a real screen, ask them to read the last line aloud to you and then say the line number before touching the keyboard. It builds the habit of treating it as a clue.
Open these notes on screenScan the code, or go to tutorpip.com.