Testing & Errors
Code never works the first time. We perform Iterative Testing to hunt bugs during development, and identify them as either catastrophic Syntax Errors or stealthy Logic Errors.
The Two Types of Errors
Syntax Error
You broke the spelling/grammar rules of the language. The Translator cannot understand you. The code immediately crashes.
print("Hello World"
>> SyntaxError: unexpected EOF
Logic Error
The grammar is perfect so the programme runs completely fine, but the algorithm gives you the wrong answer.
area = width + height
>> Output is wrong, but it doesn't crash.
Examiner's Eye - The Definitions
If asked to define Iterative vs Final Testing: Iterative means "during development, testing individual modules/lines". Final/Terminal means "at the end of development, testing the WHOLE completed system against original requirements".
The Bug Hunter IDE
Below are two Python files. File 1 refuses to run. File 2 runs, but the boss is complaining the 'Average' is wrong. Click the exact error in the code to fix it.
pwd = input("Password: ")
if pwd == "admin"
prnt("Success")
num1 = 10
num2 = 20
# Error is on line below!
avg = num1 + num2 / 2
print("Average is:", avg)
Check Your Understanding
1. You have just finished writing a subprogramme to process a user's payment. Before moving on to the next feature, you run a test using sample card details to ensure this specific module works. What type of testing is this?
2. You write a program with the line WHILE score > 10. You forget to put the colon at the end. When you hit 'Run', the screen flashes red and refuses to execute. What type of error is this?
Written Exam Scenario (AO2/AO3)
Stretch (Grade 9)"A school programmer writes the following algorithm to output the word 'Pass' if a student scores 50 or MORE on their test. It runs, but when entering exactly '50', it outputs 'Fail'.
score = input()
IF score > 50 THEN
print('Pass')
ELSE
print('Fail')
Identify the type of error present and explain how to fix the code." (3 marks)
Type of Error: It is a Logic Error.
Explanation: The algorithm executes without crashing (no syntax issues), but produces the wrong outcome because the boolean operator is incorrect.
The Fix: The IF statement condition should be changed from strictly greater than > 50 to greater than OR equal to >= 50.