GCSE · Computer Science · AQA · Spec 8525
Syntax errors
Leave one colon off one line, and not a single line of your program will run. Get a sum completely wrong, though, and it runs without a murmur. Why?
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 translator only recognises the exact spelling. To it, a keyword with one letter missing 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 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. It can only do that if every line follows the language's rules. Here is a four-line Python program 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 watch 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 the way code is written. It breaks the grammar rules of the programming language, so the statement is not valid in that language.
- Typical causes: a misspelt keyword or identifier; a missing or unmatched bracket or quotation mark; missing punctuation the language requires, such as a colon or semicolon; and incorrect indentation, in languages where indentation is part of the syntax.
- Syntax errors are detected by the translator (a compiler or an interpreter). A program containing a syntax error cannot be translated and run until the error is corrected.
- The translator usually reports the line where it found the problem. That's where to start looking.
- A logic error lets the program run but produces incorrect or unexpected results. The translator doesn't report it, so it must be found by testing.
- To correct a syntax error, find the line that breaks a rule 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. Typical causes 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 different: the code follows the rules and runs, but gives wrong results, so only testing finds 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 from running at all.
Memory hook
The translator is a ticket barrier. It checks that 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?
Name four typical causes of syntax errors.
What detects syntax errors?
Can a program with a syntax error run?
When the 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 30 September 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.