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.

10 of 10 still to sort.

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.

Watch out: Don't put a line in a syntax category just because its answer is wrong. Ask first: is it written by the rules? If it is, the problem is the logic.

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?

LineCodeTranslatorLines run
1name = input("What is your name? ")✓ follows the rules0

Output

 

Step 1: Before anything runs, the translator reads through the program, checking each line against the language's rules. Line 1 is fine.

1 / 10

Use Next to step through, and watch the Lines run column.

Step 1 of 10: Before anything runs, the translator reads through the program, checking each line against the language's rules. Line 1 is fine..

Your turn

Find the line that won't translate

This Python quiz program won't run. Exactly one line breaks the language's rules. Which one?

A student's program — which line goes wrong?

Syntax error or logic error?

Syntax errorvsLogic error

Tap a row's insight to see why the difference matters.

Focus

What's actually wrong

Syntax error

How the code is written: it breaks the language's rules.

Logic error

What the code does: it follows the rules but does the wrong thing.

The insight

Syntax is about the writing. Logic is about the thinking behind it.

Can the program run?

Syntax error

No. It can't be translated and run until the error is corrected.

Logic error

Yes. It runs, but the results are incorrect or unexpected.

Does the translator report it?

Syntax error

Yes, usually with the line where it found the problem.

Logic error

No. As far as the rules go, nothing is wrong.

How is it found?

Syntax error

The translator reports it when you try to translate the program.

Logic error

By testing: running the program and checking the results.

What do you really think?

It ran without a single error message

Priya's program asks for three test scores and prints their average. It translates and runs, with no error messages at all. But when she types 6, 7 and 8, it prints 10.5.

Which is closest to what you think is going on?
How sure are you?

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

1Syntax error: how the code is written. Logic error: what the code does.
2One syntax error anywhere and the program can't be translated and run.
3The translator reports syntax errors, usually with the line where it found the problem. Fixing them is the programmer's job.
4A program that runs has no syntax errors, but it can still have logic errors.

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?
A mistake in the way code is written that breaks the grammar rules of the programming language, so the statement isn't valid in that language.
Name four typical causes of syntax errors.
A misspelt keyword or identifier; a missing or unmatched bracket or quotation mark; missing punctuation the language requires (such as a colon or semicolon); incorrect indentation where indentation is part of the syntax.
What detects syntax errors?
The translator: a compiler or an interpreter.
Can a program with a syntax error run?
No. It can't be translated and run until the error is corrected.
When the translator finds a syntax error, what does it usually tell you?
The line where it found the problem.
What is a logic error?
An error that lets the program run but makes it produce incorrect or unexpected results.
Why doesn't the translator report logic errors?
The code follows the language's rules, so there's nothing for it to reject. It checks how the code is written, not what it does.
How are logic errors found?
By testing: running the program and checking whether the results are what was expected.
Syntax or logic? print("Done"
Syntax: the bracket is never closed. Correct it to print("Done").
Syntax or logic? A line meant to double n reads: double = n + 2
Logic: it follows the rules and runs, but adds 2 instead of multiplying by 2. Correct it to 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 posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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.