GCSE · Computer Science · Eduqas · Spec C500QS

Logical errors

Press Run. No red text, no warnings, an answer on the screen. So the program must be right, mustn't it? Try it and find out.

Computer Science · Logical errors

It ran. So is it right?

This program should print the mean of the two numbers a and b. Work out the mean yourself first. Then press Run and compare.

Python
  1. a = 10
  2. b = 20
  3. mean = a + b / 2
  4. print("Mean:", mean)

The messages and outputs are what Python 3.11 gives for this exact code.

Computer Science · Finding logical errors

Test the ticket program

The rule: anyone aged 18 or over pays the adult price. Is the code doing that?

Choose an input. The rule says 18 or over gets the adult ticket, so decide what should happen before you commit to what the code does.

age = int(input("Enter your age: "))
if age > 18 then
print("Adult ticket")
else
print("Junior ticket")
endif

Variables

age=25

Step 1. The user types 25, and it is stored in age.

Step 1 of 4Called right: 0 of 1

Read the condition on line 2 exactly as it is written, not as the rule is worded.

Computer Science · Locating the fault

The total that is 5 short

This program should print the total of 1 + 2 + 3 + 4 + 5, which is 15. It prints Total: 10, with no error message. Which line is at fault?

A program with one fault — which line goes wrong?

Exam line: Dry-run the loop: list each value of the loop variable and the running total, and check the first and last passes against what you expect.

Computer Science · What do you think?

The program ran. Now what?

A program has run. There was no error message and an answer is on the screen, but the answer is not the one the programmer expected.

Which is closest to what you think right now?
How sure are you?

Exam line: Say that the translator checks the rules of the language, that the computer did exactly what was written, and that testing is how the wrong output is found.

Computer Science · Your turn

Write it in your own words

Describe what a logical error is and describe how one can be found. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

Exam line: Cover four things: the fault is in the reasoning, the translator accepts the code, the output is wrong, and testing finds it.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

The program runs, nothing complains, and the answer is still wrong.

What you need to know

  • A logical error is a mistake in a program's design or reasoning, not in the rules of the programming language.
  • The code still obeys the syntax rules, so the translator accepts it and gives no error message.
  • Have a goYour mate says: "It ran with no red text, so my program is perfect." What has the translator actually checked?

    Only that the code obeys the rules of the language.

    No message tells you the rules were followed. It says nothing about whether the reasoning behind the code is right.

  • Normally the program runs and gives wrong output, though a loop whose condition never becomes false can stop it finishing.
  • Either way, the program gives a wrong or unexpected result, or behaves differently from what the programmer intended.
  • Have a goA program should double a number but the programmer wrote x * 3. What does the translator say when you run it?

    Nothing. It runs and gives the wrong result.

    x * 3 obeys the rules of the language, so there is no message. The fault is in the reasoning, and only the output shows it.

  • The fault is in the algorithm or the reasoning: the computer carries out exactly what was written, and that does not solve the problem.
  • A translator cannot detect a logical error, so it shows up only in the output or the behaviour.
  • Wrong comparison operator: IF age > 18, when the rule is 18 or over (age >= 18), handles exactly 18 wrongly.
  • Missing brackets: a + b / 2 instead of (a + b) / 2 runs, but the order of operations gives a wrong mean.
  • Have a goWork out a + b / 2 when a is 6 and b is 10. Is that the mean of 6 and 10?

    11, and no: the mean is 8.

    Division happens before addition, so only b is halved: 10 / 2 is 5, then 6 + 5. The mean needs the brackets: (6 + 10) / 2.

  • A loop that repeats one time too few or too many also gives an incorrect result.
  • Testing finds logical errors: run with test data whose expected results are known, compare actual with expected, or dry-run with a trace table.

The big picture

A logical error is a mistake in a program's design or reasoning. The code obeys the rules of the language, so the translator accepts it with no message, and the fault shows up only as wrong output or behaviour. You find it by testing against results you already know.

Key points

1A logical error is a fault in a program's design or reasoning that the translator accepts without any message.
2It shows up as wrong or unexpected output or behaviour, because the computer does exactly what was written.
3It is found by testing with known expected results, or by dry-running with a trace table.
4Typical causes: a wrong comparison operator, missing brackets in a calculation, or a loop repeating the wrong number of times.

Worked example

Problem

A program should print the area of a rectangle with width 4 and height 3. The code is: area = width + height, then print(area). It runs with no message and prints 7. Show that it has a logical error and find the fault.

⚠ Watch out

Thinking that a program with no error message must be correct. The translator checks only the rules of the language, so a program can run perfectly and still give the wrong answer.

🧠

Memory hook

The translator checks the rules. Only you, with test data, can check the reasoning.

✓

Check yourself

A program should print the larger of 3 and 8, but it prints 3 with no message. Is that a logical error, and how do you know?

Flashcards

(12)
What is a logical error?
A mistake in a program's design or reasoning, not in the rules of the programming language.
Why does the translator accept a program with a logical error?
The code obeys the syntax rules, so the translator has nothing to report and gives no message.
What does a program with a logical error normally do when you run it?
It runs but produces wrong output.
Can a logical error stop a program finishing?
Yes, sometimes. A loop whose condition never becomes false is an example.
Where is the fault in a logical error?
In the algorithm or the programmer's reasoning. The computer does exactly what was written.
Can a translator detect a logical error?
No. The error shows up only in the output or behaviour.
Logical error example: IF age > 18 when the rule is 18 or over.
The wrong comparison operator. The rule needs age >= 18, so an input of exactly 18 is handled wrongly.
Logical error example: a + b / 2 for the mean of a and b.
Order of operations gives a wrong answer. It must be (a + b) / 2.
Logical error example: a loop repeating the wrong number of times.
One time too few or too many gives an incorrect result.
How are logical errors found?
By testing: run with test data whose expected results are known and compare actual with expected output, or dry-run with a trace table.
What do you need before you can spot wrong output?
The expected result, worked out beforehand. Without it you cannot tell wrong output from right.
What is a trace table for?
Dry-running an algorithm step by step, recording the values as you go, to see where it goes wrong.

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 Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 16 November 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.