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.
- a = 10
- b = 20
- mean = a + b / 2
- 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 thenprint("Adult ticket")elseprint("Junior ticket")endif
Variables
Step 1. The user types 25, and it is stored in age.
Read the condition on line 2 exactly as it is written, not as the rule is worded.
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
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?
Why does the translator accept a program with a logical error?
What does a program with a logical error normally do when you run it?
Can a logical error stop a program finishing?
Where is the fault in a logical error?
Can a translator detect a logical error?
Logical error example: IF age > 18 when the rule is 18 or over.
Logical error example: a + b / 2 for the mean of a and b.
Logical error example: a loop repeating the wrong number of times.
How are logical errors found?
What do you need before you can spot wrong output?
What is a trace table for?
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 Eduqas GCSE Computer Science topics
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.