Every programmer, at every level, sees errors. For a child, the red text can feel like being told off. The trick is to see an error message as a clue, not a verdict. Here are the eight mistakes children make most often, with what Python is trying to tell them.
1. NameError: name is not defined
player = "Maya"
print(plyer)Python says NameError: name 'plyer' is not defined. It means you used a name that doesn't exist, usually a typo or a variable you forgot to create. Fix: check the spelling matches exactly.
2. IndentationError
for i in range(3):
print(i)Python expects the line after a colon to be indented. Fix: put four spaces (or press Tab) in front of lines inside a loop, an if or a function.
3. SyntaxError: a missing colon
if score > 5
print("Nice!")Python points at the end of the if line. Fix: add a colon : at the end of if, else, for, while and def lines.
4. Using = instead of ==
if color = "red":
print("Stop")A single = stores a value; two (==) ask a question. Fix: use == inside an if.
5. Forgetting quotation marks (or leaving them open)
print("Hello)An unclosed quote makes Python read on looking for the end. Fix: make sure every opening quote has a matching one.
6. TypeError: mixing text and numbers
age = 9
print("I am " + age)You can't add text and a number. Fix: convert, or use a comma:
print("I am " + str(age))
print("I am", age)7. Capital letters matter
Print("Hi") fails because the function is print, all lower case. Variable names are case-sensitive too: Score and score are different.
8. Off by one
range(5) gives 0, 1, 2, 3, 4, not 1 to 5. Lists also start counting at 0, so the first item of pets is pets[0]. Fix: remember zero-based counting, and use range(1, 6) for 1 to 5.
How to read any error
Teach your child this routine:
- Look at the last line. It names the kind of error and gives a short explanation.
- Look for the line number. Python tells you where it got confused. The real mistake is often on that line or just above it.
- Read the code aloud as if you were the computer, doing exactly what it says.
How to help without taking over
Ask: "What do you think the error is saying?" before suggesting anything. If your child has to explain it to you, they will usually spot the fix themselves.
Finding and fixing your own bugs is a skill that builds confidence. Read more in how to help your child when they're stuck and debugging for kids, or practise spotting bugs in the Tiny Coderz Puzzle Arcade.