Pearson Edexcel · GCSE · Computer Science
Course version: 1CP2 · Version from Sept 2020
Be able to identify, locate and correct program errors (logic, syntax,…
Full specification wording
Develop code: 6.1.5 be able to identify, locate and correct program errors (logic, syntax, runtime)
Debugging means finding why a program does not behave as intended, working out where the fault is, and fixing it.
Checked against the Pearson Edexcel 1CP2 specification (opens in a new tab) on .
- Point 2 of 2
- 4 key terms
Study notes
From the checked teaching notes for this specification point.
The idea
Debugging means finding why a program does not behave as intended, working out where the fault is, and fixing it. Syntax errors break the rules of the language, so the program will not run; an example is a missing closing bracket or a misspelled keyword. Logic errors let the program run but produce wrong results, such as using addition where subtraction is needed or writing a condition that is never true. Runtime errors occur while the program is running, for example dividing by zero or accessing an index outside the bounds of a list. To debug, read the error message, trace the values of variables, add temporary output statements, and test with known inputs. Once the fault is located, correct the code and re-test to confirm the fix and check that nothing else has broken.
What earns the marks
- Syntax errors: the code breaks language rules, so it fails to run; examples include missing brackets or misspelled keywords.
- Logic errors: the program runs but gives incorrect output, such as a wrong operator or a faulty condition.
- Runtime errors: the fault appears while running, such as division by zero or an out-of-range list index.
- Locating errors: use error messages, trace tables, temporary output and test data to find the faulty line.
- Correcting errors: change the code so it follows the rules, produces the intended result, or handles the failing case.
- Verification: re-run the program with normal, boundary and erroneous test data to confirm the correction.
Common mistakes and how to put them right
Treating every error as a syntax error.
Put it right: Check whether the program runs at all; if it runs but gives wrong output, suspect a logic error, and if it crashes mid-run, suspect a runtime error.
Assuming a runtime error is always on the line shown in the message.
Put it right: The reported line may be where the fault surfaces, so trace back to the value or index that caused it.
Fixing a symptom rather than the cause, such as changing an output value instead of the calculation.
Put it right: Locate the faulty statement and correct the underlying logic, then re-test.
Exam tips
- Classify the error first: does the program fail to run, run with wrong output, or crash while running? The category guides the fix.
- Use a trace table or add temporary output to follow variable values and pinpoint the line where behaviour diverges from expectation.
- After correcting, re-test with the original failing input plus a normal case to show the fix works and has not introduced a new fault.
Try the lesson
The start of the Develop code: 6.1.5 be able to identify, locate and correct program errors (logic, syntax, runtime) lesson, made from checked teaching notes for this specification point.
Have a go first
A student writes this Python code to add the numbers 1, 2 and 3. The intended output is 6.
score = 0 for i in range(1, 4) score = score + i print(score)
When the program is run, Python reports a syntax error and no output is shown. Which correction fixes the error?
Listen
Debugging means finding why a program does not behave as intended, working out where the fault is, and fixing it. Syntax errors break the rules of the language, so the program will not run; an example is a missing closing bracket or a misspelled keyword. Logic errors let the program run but produce wrong results, such as using addition where subtraction is needed or writing a condition that is never true. Runtime errors occur while the program is running, for example dividing by zero or accessing an index outside the bounds of a list. To debug, read the error message, trace the values of variables, add temporary output statements, and test with known inputs. Once the fault is located, correct the code and re-test to confirm the fix and check that nothing else has broken. A strong answer earns marks for these points. Syntax errors: the code breaks language rules, so it fails to run; examples include missing brackets or misspelled keywords. Logic errors: the program runs but gives incorrect output, such as a wrong operator or a faulty condition. Runtime errors: the fault appears while running, such as division by zero or an out-of-range list index. Locating errors: use error messages, trace tables, temporary output and test data to find the faulty line. A common slip: Treating every error as a syntax error. Instead, check whether the program runs at all; if it runs but gives wrong output, suspect a logic error, and if it crashes mid-run, suspect a runtime error. Exam tip: Classify the error first: does the program fail to run, run with wrong output, or crash while running? The category guides the fix.
Key words
Say what each word means before you turn the card.
Syntax errors
Try answering aloud or in your head before turning the card.
Logic errors
Try answering aloud or in your head before turning the card.
Runtime errors
Try answering aloud or in your head before turning the card.
Debugging
Try answering aloud or in your head before turning the card.
See every definition
- Syntax errors
- Errors where the code breaks the rules of the language, so the program will not run, such as a missing closing bracket or a misspelled keyword.
- Logic errors
- Errors that let the program run but produce wrong results, such as using addition where subtraction is needed or a condition that is never true.
- Runtime errors
- Errors that occur while the program is running, for example dividing by zero or accessing an index outside the bounds of a list.
- Debugging
- Finding why a program does not behave as intended, working out where the fault is, and fixing it by reading error messages, tracing variables and testing with known inputs.
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of Develop code: 6.1.5 be able to identify, locate and correct program errors (logic, syntax, runtime)
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge