GCSE · Computer Science · Edexcel · Spec 1CP2

Identifying and correcting program errors

Your program runs. No red text, no crash. So it must be right... mustn't it? Let's see how a test catches a bug no error message mentions.

Computer Science · Testing and debugging

Test 3 fails: follow the bug

A made-up bike-hire program. Test table row: Test 3 · negative number of days · input -3 · expected output Rejected. The output box keeps everything printed so far, so you can see both runs.

The hire shop only hires bikes for 1 to 14 days. Before you press Next: what should the program do with -3?

1 # Version 1: the first attempt
2 days = int(input("Days: "))
3 print("Cost: £" + str(days * 5))
4 # Version 2: after debugging
5 days = int(input("Days: "))
6 if days < 1 or days > 14:
7 print("Rejected")
8 else:
9 print("Cost: £" + str(days * 5))

Variables

days=-3actual=—result=—expected=Rejected

Output

 

Step 1: Test 3 from the test table: the input is -3 days, and the expected output is Rejected. Line 1 reads the input, so days now holds -3.

1 / 6

Press Next to move one step at a time. The chips show the test row: days is the input, then expected, actual and the result.

Step 1 of 6: Test 3 from the test table: the input is -3 days, and the expected output is Rejected. Line 1 reads the input, so days now holds -3..

Watch out: Version 1 gave no error message at all. The failing test was the only clue that anything was wrong.

Telling the three error types apart

Which error is which?

Tick every property that fits each type of error, then check your grid. Three properties, three types, and only some cells are true.

Syntax error
Logic error
Runtime error

Exam line: Only a syntax error is flagged before the program runs; a logic error gives no message at all; a runtime error needs the program to be run.

Hunting a logic error

No message. Wrong answer.

This illustrative program should print Discount for anyone aged under 12 or over 65. It runs with no error message, but an 8-year-old gets Full price. Which line is faulty? Trace it with age = 8 if you're stuck.

A made-up cinema program — which line goes wrong?

Exam line: No error message does not mean no error: trace the suspect line with a real value.

Choosing test data

Normal, boundary or erroneous?

The bike-hire program should accept a whole number of days from 1 to 14. Pick a test value, then pick the kind of test data it is.

Still to sort

Normal (0)

Valid data that should be accepted.

Where the line is: Normal data is valid and not on an edge. Edge values are boundary data, even though some are accepted.

Boundary (0)

On the edge of being valid: on or just inside is accepted, just outside is rejected.

Where the line is: Boundary data sits on the edge. A word typed instead of a number is erroneous, not boundary.

Erroneous (0)

Data that should not be accepted because it would cause an error.

Where the line is: Erroneous data is the wrong kind of thing, such as a string where an integer is required. A number just outside the range is boundary data.

8 of 8 still to sort.

Predict, then check

Two modules, each tested and each passing. Commit before you look.

Two modules were written separately and each passed all of its own tests. They are now joined into one program. Which is true?

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

A program can run perfectly and still be wrong. Here's how a test catches it and how you fix it.

What you need to know

  • A bug is an error in code that stops it working as expected; debugging is finding and correcting errors.
  • Testing is the systematic process of checking that a program works as expected, and it is how errors are identified.
  • Syntax errors break the rules of the language. The translator flags them, so the program will not run.
  • Logic errors let the program run but give an unexpected result, and the IDE cannot pick them up.
  • Runtime errors happen when the program is run: the code is valid and logical, but the input or environment causes the error.
  • Have a goSam says: 'My program printed no error message, so it must be perfect.' Which of the three error types could Sam still have?

    Two of them: a logic error, or a runtime error. Only a syntax error is ruled out.

    A syntax error would stop the program running. A logic error runs to the end with a wrong result the IDE cannot pick up. A runtime error only appears with certain input or environments, so this run may have missed it.

  • To debug: find the error, read the message, trace the code to where it occurs, fix it, then run it again to check.
  • A test table records the test number, description, input data, expected output, actual output and, if the test failed, how it was fixed.
  • Have a goIn a test, the expected output is 15 and the actual output is 15. Which test table column can stay empty for that test?

    The 'how it was fixed' column.

    That column is only filled in if the test failed. A passing test has nothing to fix, though its actual output is still recorded.

  • Normal data is valid and should be accepted; erroneous data should not be accepted, like a string where an integer is needed.
  • Boundary data sits on the edge of valid: on or just inside gets accepted, just outside gets rejected.
  • Have a goAn age box accepts whole numbers from 13 to 17. A tester tries 15 and 18. Which is boundary data, and should it be accepted?

    18: it is just outside the edge, so it should be rejected.

    15 is normal data, valid and nowhere near an edge. Boundary data sits on the edge, and values just outside it should be rejected.

  • Iterative testing checks each section as it is written; integration testing checks that separately tested modules work together.

The big picture

A bug is an error in code, and 'it ran without an error message' does not mean 'it is correct'. Testing compares the expected output with the actual output, using normal, boundary and erroneous data. When they differ you debug: trace the code, fix the error, then run the test again. Syntax, logic and runtime errors behave differently, and testing goes on throughout development, section by section and again when modules are combined.

Key points

1Expected output against actual output is how a test finds a bug, even when there is no error message.
2Syntax errors are flagged by the translator, logic errors give an unexpected result without a message, and runtime errors come from the input or environment.
3Debugging: find the error, read the message, trace the code, fix it, then run it again to check the fix works.
4Choose normal, boundary and erroneous test data, and record each test in a test table.
5Test throughout development: each section as it is written, and the modules together once they are combined.

Worked example

Problem

A short program should print the total of the numbers 1 to 5. In the test table, Test 1 has expected output 15 and actual output 10. The code is: total = 0, then for number in range(1, 5): total = total + number, then print(total). Find the error, fix it and prove the fix works.

⚠ Watch out

Thinking that a program with no error message must be correct. A logic error gives no message at all, and a runtime error only appears with certain input or environments. Only comparing actual output with expected output, across normal, boundary and erroneous data, shows you what your program really does.

🧠

Memory hook

Expected, Actual, Trace, Fix, Retest: if the first two differ, trace the code, fix the cause, then run the same test again.

✓

Check yourself

A program runs to the end with no error message but prints the wrong total. Name the error type, say why the IDE missed it, and list what you would do next.

Flashcards

(14)
What is a bug?
An error or mistake in code that stops it from working properly or as expected.
What is debugging?
The process of finding and correcting errors in program code.
What is testing?
The systematic process of checking that a program works as expected. It is how errors are identified.
What is a syntax error?
An error where the rules of the language have not been followed. The translator flags it and the program will not run. A missing speech mark is an example.
What is a logic error?
An error that makes the program work incorrectly: it runs without failing but does not return the expected result. The IDE cannot pick it up.
What is a runtime error?
An error that occurs when the program is run. The code is valid and logically correct, but the environment or the input provided causes the error.
Which logic error causes does this lesson name?
Misunderstanding what the program needs to do, using the wrong logical operator in a selection statement, and loops that run more or fewer times than intended.
What are the steps of debugging?
Find the error, read the error message, trace through the code to detect where it occurs, fix the error, then run the code again to check the fix works.
What does a test table record?
A test number, description, input test data, expected output, actual output and, if the test failed, how it was fixed.
What is normal test data?
Valid data that should be accepted.
What is boundary test data?
Values on the edge of being valid. Values on or just within the boundary are accepted; values just outside are rejected.
What is erroneous test data?
Data that should not be accepted because it would cause an error, such as a string where an integer is required.
What is iterative testing?
Testing each section as it is written and resolving errors before the next section is developed.
What is integration testing?
Checking that separately tested modules work correctly together, because a module that works alone may cause errors when combined into a wider system.

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

See the full Edexcel Computer Science curriculum →

How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 21 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.