GCSE · Computer Science · AQA · Spec 8525
Syntax errors
Leave one colon off a Python program and not one line runs. Get a sum totally wrong, though, and it runs without a murmur. What's going on?
Programming · Errors
What's wrong with this line?
Every line below is Python, and each has one thing wrong with it. Most break a grammar rule of the language: that's a syntax error. A few follow every rule but don't do what they were meant to. Pick a line, then pick what's wrong with it.
Still to sort
Misspelt keyword (0)
A keyword is a word with a fixed meaning in the language, like if, while or for. Here one is spelt wrongly.
Where the line is: The language only recognises the exact spelling. A keyword with one letter out isn't nearly right. It's meaningless.
Bracket or quotation mark (0)
Brackets and quotation marks come in pairs. One is missing or doesn't match.
Where the line is: Count the openers and the closers. Every ( needs a ), and a piece of text that opens with " must close with ".
Missing punctuation (0)
The language needs a symbol here and it isn't there, like the colon at the end of an if, while or for line. Some languages need a semicolon instead.
Where the line is: The words are all spelt right and every pair is closed. What's missing is a single symbol the rules demand.
Wrong indentation (0)
In languages like this one, the spaces at the start of a line are part of the rules.
Where the line is: Indentation means the spaces at the start of a line. Here, indenting a line is how you show it belongs inside an if or a loop. Spaces between the words don't count.
Logic error: runs, but gives the wrong result (0)
Written perfectly by the rules. It just doesn't do what it was meant to.
Where the line is: If nothing about the way it's written is broken, it isn't a syntax error, however wrong the answer is.
Under each line is what the programmer meant it to do. You'll need that for the logic errors: a line can only be doing the wrong thing if you know what the right thing was.
Programming · The translator
One missing colon. How much of the program runs?
A translator (a compiler or an interpreter) turns your code into something the computer can carry out, and it can only do that if every line follows the language's rules. Here's a four-line Python program, run as one file, with one mistake in it.
Predict first: the mistake is on line 3. Will lines 1 and 2 run before the translator gets there?
| Line | Code | Translator | Lines run |
|---|---|---|---|
| 1 | name = input("What is your name? ") | ✓ follows the rules | 0 |
Output
Step 1: Before anything runs, the translator reads through the program, checking each line against the language's rules. Line 1 is fine.
Use Next to step through, and keep an eye on the Lines run column.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
One missing character, and the whole program refuses to start.
What you need to know
- A syntax error is a mistake in how code is written. It breaks the language's grammar rules, so the statement isn't valid.
- Misspelt keywords or identifiers cause them: write whle instead of while and the line stops making sense to the language.
- Missing or unmatched brackets or quotation marks are another cause. Every ( needs its ), and every opening " needs a closing one.
- So is missing punctuation the language requires, such as the colon at the end of an if line, or a semicolon.
Have a goJay has stared at if lives == 0 for ten minutes and swears every word is spelt right. Jay's correct. So why won't it translate?
It's missing the colon: if lives == 0:
Perfect spelling isn't enough. The rules also demand the colon that ends an if line, and leaving out a required symbol is still a syntax error.
- In languages where indentation is part of the syntax, like Python, incorrect indentation is a syntax error too.
- Syntax errors are detected by the translator: a compiler or an interpreter.
- Until it's corrected, a program containing a syntax error can't be translated and run.
- Translators usually report the line where they found the problem. That's where you start looking.
Have a goThe translator reports a problem on line 12. Can you be certain the mistake is on line 12?
Not certain. Line 12 is where it found the problem, so start looking there.
Translators usually report the line where they found the problem. 'Usually' means it's the best place to start, not a promise.
- Logic errors are different: the program runs but gives incorrect or unexpected results. The translator doesn't report them, so testing must find them.
Have a goA program meant to add two numbers prints 5 when you type 7 and 2. No error messages. Syntax error or logic error?
Logic error.
It ran and printed something, so every line follows the rules. It's working out 7 − 2 instead of 7 + 2: wrong in what it does, not in how it's written.
- To correct a syntax error, name the line and say exactly what to change, for example 'add a colon to the end of line 3'.
The big picture
A syntax error is a mistake in how code is written: it breaks the programming language's grammar rules. The usual culprits are misspelt keywords or identifiers, missing or unmatched brackets or quotation marks, missing punctuation such as a colon, and wrong indentation where indentation is part of the syntax. The translator detects it, usually reporting the line where it found the problem, and the program can't be translated and run until it's fixed. A logic error is a different beast: the code follows the rules and runs, but gives wrong results, so testing has to find it.
Key points
Worked example
Problem
This Python program is meant to print the larger of two numbers. Line 1: a = int(input("First number: ")) Line 2: b = int(input("Second number: ")) Line 3: if a > b: Line 4 (indented): print(b) Line 5: esle: Line 6 (indented): print(a) Find the syntax error and say how to correct it. Then decide whether the program will do its job once that's fixed.
⚠ Watch out
Calling every bug a syntax error. If the program runs and gives a wrong answer, the code follows the rules, so it's a logic error. A syntax error stops the program being translated and run at all.
Memory hook
The translator is a ticket barrier. It checks your ticket is valid, and until it is, not one line gets through. It never checks whether you're on the right train. Valid ticket = syntax. Right train = logic.
Check yourself
Cover the page. Name three causes of syntax errors, say what happens when you try to run a program containing one, and explain why a program that runs can still be wrong.
Flashcards
(10)What is a syntax error?
What typically causes syntax errors?
Which software detects syntax errors?
Can a program with a syntax error run?
A translator finds a syntax error. What does it usually tell you?
What is a logic error?
Why doesn't the translator report logic errors?
How are logic errors found?
Syntax or logic? print("Done"
Syntax or logic? A line meant to double n reads: double = n + 2
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 28 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.