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.

10 of 10 still to sort.

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.

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, 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?

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 keep an eye on 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 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

1Syntax error: how the code is written. Logic error: what the code does.
2A syntax error means the program can't be translated and run until it's corrected.
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 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?
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.
What typically causes syntax errors?
A misspelt keyword or identifier; a missing or unmatched bracket or quotation mark; missing punctuation the language needs (such as a colon or semicolon); incorrect indentation where indentation is part of the syntax.
Which software 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.
A translator finds a syntax error. What does it usually tell you?
The line where it found the problem: your starting point for the hunt.
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 you 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 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.