Book a lesson
HomeResourcesPython Emergency Kit
GCSE Computer Science ยท Python Debugging

Python Emergency Kit

Fix the 5 most common Python errors instantly. Written so any parent can sit alongside their child and help โ€” no technical experience needed.

Book a Python sessionPython for Beginners

What this covers

IndentationError โ€” why Python shouts about spaces
NameError โ€” the missing variable mystery
TypeError โ€” mixing strings and numbers
SyntaxError โ€” the most common one-character mistake
IndexError โ€” going past the end of a list

How to use this guide

Each error has three parts: what it looks like, why it happens, and exactly how to fix it. Start with the error Python is showing you โ€” jump straight to that section.

Reading the error message

Python always tells you: (1) the error type, (2) the line number, (3) what went wrong. Most students ignore the message and guess. Reading it takes 10 seconds and usually shows you exactly where to look.

For parents

You do not need to understand Python to help. Read the error message with your child. Find the line number. Look at this guide. The fixes are written in plain English.

Error 1 โ€” IndentationError

"Python keeps shouting about spaces and I don't understand why."

What it looks like

if age >= 18:
print("You can vote")  # โ† No indent!
# IndentationError: expected an indented block

Why it happens

Python uses indentation (spaces at the start of lines) to show structure โ€” which lines belong inside an if, loop, or function. If the indentation is wrong or inconsistent, Python cannot understand the structure.

1
Click at the start of the problem line.Place your cursor right before the first character.
2
Press Tab (or type 4 spaces).Every line inside an if, for, while, or def block must be indented by 4 spaces.
3
Check consistency.All lines at the same level must have exactly the same indentation. Mixing tabs and spaces causes errors โ€” use spaces only.
4
Use View โ†’ Show Whitespace.In most editors this reveals invisible spaces. Turn it on permanently while learning.

Error 2 โ€” NameError

"But I used that variable right there! Why does Python say it doesn't exist?"

What it looks like

print(score)  # โ† Using before creating
score = 100
# NameError: name "score" is not defined

Why it happens

Python reads your code top to bottom, line by line. If you use a variable before you've created it, Python genuinely does not know what it is yet. Spelling matters too โ€” Score and score are different variables.

1
Check the line number in the error.Go to exactly that line.
2
Look upward from that line.Is the variable created somewhere above it? If not, you need to create it first.
3
Check spelling carefully.Score, score, and SCORE are three different variables in Python. One typo causes this error.
4
Check indentation of the creation.If the variable is created inside an if block, it only exists inside that block.

Error 3 โ€” TypeError

"I'm trying to add things together and Python is complaining."

What it looks like

age = input("How old are you? ")
if age >= 18:  # โ† TypeError!
# TypeError: ">=" not supported between str and int

Why it happens

input() always returns a string โ€” even if the user types a number. "18" the string and 18 the integer are different things. You cannot compare or do maths on them without converting.

The fix

Wrap input() with int() when you need a number: age = int(input("How old are you? ")). Use float() for decimal numbers. Use str() to convert a number back to text for display.

Error 4 โ€” SyntaxError

"Python says there's an error but the line looks fine to me."

1
Check the line ABOVE the error.SyntaxError often points to the line after the real problem. A missing colon on an if statement shows as an error on the next line.
2
Look for missing colons.Every if, for, while, def, and else line must end with a colon. This is the most common SyntaxError.
3
Check brackets are paired.Every ( needs a ). Every [ needs a ]. Every { needs a }. Count them.
4
Check quote marks.Every string must start and end with the same quote mark. "Hello' causes a SyntaxError.

Common SyntaxError causes

if x = 5:   # โ† Should be ==
for i in range(5)  # โ† Missing colon
print("Hello)  # โ† Missing closing quote

Parent tip

SyntaxError is almost always one missing character. Scan the flagged line character by character. If nothing is obvious, look at the line above.

Error 5 โ€” IndexError

"My list exists and has things in it โ€” why is Python saying the index is out of range?"

What it looks like

names = ["Ali", "Beth", "Carlos"]
print(names[3])  # โ† IndexError!
# IndexError: list index out of range
# (List has 3 items: index 0, 1, 2)

Why it happens

Python lists start at index 0, not 1. A list with 3 items has indexes 0, 1, and 2. Index 3 does not exist. This is called zero-indexing and trips up almost every beginner.

1
Remember: first item is index 0.names[0] is "Ali". names[1] is "Beth". names[2] is "Carlos".
2
Last item is len(list) - 1.If the list has 3 items, the last valid index is 2, not 3.
3
Use len() to be safe.When looping, use range(len(names)) rather than guessing the length.
4
Print the length.Add print(len(names)) to see exactly how long your list is.

Still stuck after checking all five?

Sometimes an error needs a second pair of eyes. Miss ICT Python sessions work through exactly these problems โ€” calmly, clearly, and at your pace.

Book a Python sessionPython Support page

Frequently asked questions

Why does the error point to the wrong line?

Python finds errors when it tries to compile your code. By that point, the damage from a missing character several lines earlier has already propagated. Always check the line above and below the flagged line.

My code runs but gives wrong answers โ€” is that a Python error?

No โ€” that is a logic error. Python is doing exactly what you told it to do, but what you told it is not what you meant. Add print() statements to show what your variables actually contain at each step.

Why does Python care so much about indentation?

Other languages use brackets to show structure. Python chose indentation instead โ€” it makes code more readable. The trade-off is that spaces matter more. 4 spaces per indent level, consistently.

Related resources

Book a session โ†’
โœ” GCSE examiner ยท โœ” DBS checked