Library Computer Science 0478 Identifying Errors
O Level · Computer Science 0478

Identifying Errors

Revise Identifying Errors for Computer Science 0478 (O Level) — revision notes and instant AI marking. Free to start.

📖 Revision notes · preview
Cambridge IGCSE 0478 · Computer Science

Identifying Errors

Syntax, Logic & Runtime Errors — plus Algorithmic Thinking

Big idea: every mistake a program makes falls into one of three buckets — it won't run (syntax), it runs but gives the wrong answer (logic), or it runs and then crashes (runtime) — and once you can tell those apart, you can find and fix almost any bug.

📋 Quick Overview

  • Three error types exist: Syntax errors (grammar mistakes), Logic errors (wrong output), Runtime errors (crashes).
  • Syntax errors stop a program from running at all — think typos, missing brackets, missing colons.
  • Logic errors are the sneakiest — the program runs fine but gives the wrong answer. You need trace tables to hunt these down.
  • Runtime errors happen while the program is running and cause it to crash — like dividing by zero or asking for input the code can't handle.
  • Trace tables are your universal debugging tool — they help you catch all three error types by tracking variables step by step.
  • Algorithmic thinking is the skill of breaking a problem into a precise, step-by-step sequence of instructions using abstraction and decomposition.
  • Exam answers must use exact phrasing: "prevents the program from running" (syntax), "produces incorrect output" (logic), "causes the program to crash" (runtime).

1. Why This Topic Matters

Here's the thing nobody tells you when you start coding: you will never write a perfect program on the first try. Not you, not your teacher, not the engineers who built the app you're using right now. Every programmer spends huge chunks of their time hunting down bugs — and the first skill in hunting a bug is knowing what kind of bug you're even looking for.

Think of it like being a doctor. If a patient walks in, you don't just say "something's wrong" — you first work out: is this a broken bone (obvious, visible, stops them walking), an infection (they seem okay but something's off internally), or a sudden collapse (they were fine, then suddenly weren't)? Each needs a totally different fix. Programming errors work exactly the same way:

Syntax error = broken bone. Obvious. The program won't even start.
Logic error = quiet infection. The program looks fine, runs fine, but something inside is wrong — you only notice because the output is off.
Runtime error = sudden collapse. Everything's going fine, then — crash — the program dies mid-run.

Cambridge IGCSE 0478 tests this constantly, especially in Paper 2, using trace tables and "dry runs" of code. Get comfortable with the three categories and the exact vocabulary examiners want, and this becomes one of the easiest topics to pick up marks on.


2. Syntax Errors

What Is a Syntax Error?

A syntax error is an error that breaks the grammatical rules of a programming language and stops it from running at all. Programming languages are strict about grammar in a way English isn't — English lets you get away with a missing comma, but Python will refuse to even start if you forget a colon.

Think of syntax like the rules of a board game. If the rulebook says "you must roll the dice before moving," and you try to move without rolling, the game simply won't let you take that turn. It doesn't matter how clever your strategy is — you broke the rule of the game itself, so nothing proceeds.

Common causes of syntax errors Typos & spelling errors · Missing or extra brackets/quotes · Misplaced or missing semicolons/colons · Invalid variable or function names · Incorrect use of operators · Incorrectly nested loops & blocks of code

Let's look at a real example. Below is a Python program meant to generate a username from a person's first and last name. It's riddled with syntax errors — see if you can spot all four before reading on.

def generate_username(first_name, last_name)          # ← missing colon
   username = f"{first_name[0]}{last_name[0]}{last_name[:3]}"
   return username

def main():
   first_name = imput("Enter your first name: ")     # ← "imput" not "input"
   last_name = input("Enter your last name: ")
   usdrname = generate_username(first_name, last_name)  # ← typo, variable never matches
   print(f"Here's a suggested username: {username}")

main                                                   # ← missing parentheses, function never called
The four errors, explained 1. Missing colon after def generate_username(first_name, last_name) — Python requires a colon to open a function block.
2. Incorrectly spelt function nameimput should be input. Python has no function called imput, so it errors immediately.
3. Typo in variable name — the result is stored as usdrname but the print statement asks for username, which was never defined in main().
4. Missing parenthesis — writing main instead of main() refers to the function object but never actually calls it.

Here's the corrected version — notice every fix is small, but each one was blocking the whole program from running:

def generate_username(first_name, last_name):
   username = f"{first_name[0]}{last_name[0]}{last_name[:3]}"
   return username

def main():
   first_name = input("Enter your first name: ")
   last_name = input("Enter your last name: ")
   username = generate_username(first_name, last_name)
   print(f"Here's a suggested username: {username}")

main()
Practice Question 2.1

Identify the syntax error in this line of code and explain why it stops the program from running:
if age >= 18
  print("You can vote")

Practice Question 2.2

A student writes: print("Total = " + total) where total is an integer, and the program crashes with a TypeError. Is this a syntax error? Explain your reasoning.

💡 Exam Tip When asked to describe the effect of a syntax error, always use the phrase "prevents the program from running" — not "the program doesn't work" or "it's broken." Vague language loses marks.

3. Logic Errors

What Is a Logic Error?

A logic error is where the code is syntactically correct and runs perfectly fine, but it produces an incorrect output or result. This is the trickiest error type because the program doesn't announce it — no crash, no error message, nothing. It just quietly gives you the wrong answer, and you might not notice unless you check the output carefully.

Imagine following a recipe that says "bake for 25 minutes at 180°C" when it should say 350°C. You'll follow every instruction perfectly, the oven will run, nothing will crash — but you'll pull out an undercooked cake. That's exactly what a logic error feels like in code: everything executes, but the underlying instruction was wrong.

Common causes of logic errors Incorrect use of comparison operators (using < instead of >) · Logical operator confusion (using AND instead of OR, or vice versa) · Looping one extra or one too few times (off-by-one errors) · Indexing arrays incorrectly (remember: array indexing starts from 0, not 1) · Using variables before they've been assigned a value · Infinite loops (a condition that never becomes false)

How do you find logic errors? The main tool is the trace table — a table where you track the value of every variable, line by line, as the program executes. If the values diverge from what you expect at some point, that's exactly where your bug is hiding.

Let's examine a real case. This function is meant to calculate the area of a rectangle, but reject any length or width that isn't positive:

def calculate_area(length, width):
   if length < 0 or width < 0:                     # ← the bug is here
      raise ValueError("Length and width must be positive values.")
   area = length * width
   return area

The team tested it with two cases:

TestTest DataExpected OutcomeActual OutcomeChanges Needed?
1 Length = 5
Width = 5
"The area of the rectangle is approximately 25 square units." "The area of the rectangle is approximately 25.00 square units." N
2 Length = 10
Width = 0
"Length and width must be positive values." "The area of the rectangle is approximately 0.00 square units." Y — should not accept 0 as a positive input

Test 2 exposes the logic error. A width of 0 should have been rejected as "not positive," but the code let it through and calculated an area of 0.00 anyway.

The fix Logic error located on the line if length < 0 or width < 0:
The comparison < 0 should be <= 0, so that a value of exactly 0 is correctly treated as not positive and gets rejected.

This is a perfect example of why logic errors are so dangerous in the real world — a program handling money, medicine dosages, or safety systems could quietly accept a value it should have blocked, and nobody would know until something went wrong downstream.

Practice Question 3.1

A program should print numbers 1 to 5 using this pseudocode:
FOR i = 1 TO 4
  OUTPUT i
NEXT i
Identify the logic error and explain the fix.

Practice Question 3.2

A student wants to check if someone qualifies for a discount: they must be a student AND under 21. The code reads:
IF isStudent = TRUE OR age < 21 THEN
What's wrong, and how would you fix it?

💡 Exam Tip When asked to describe the effect of a logic error, use the phrase "produces incorrect output". And remember — examiners want you to name the error type, locate it (which line), and explain the impact. "The program didn't work" earns zero marks.

4. Runtime Errors

What Is a Runtime Error?

A runtime error is where an error causes a program to crash while it is running. The code was grammatically fine (it passed the syntax check and started running), but partway through execution, it hits a situation it simply cannot handle — and the whole thing stops abruptly.

Think of it like driving a car that starts up perfectly fine (no syntax error there — the engine runs) but then hits a pothole so severe it blows a tyre and the car grinds to a halt. Nothing was wrong with starting the engine; the failure only happened once you were moving and hit a specific, unhandled situation.

Common causes of runtime errors Dividing a number by 0 · Index out of the range of an array (asking for the 10th item in a 5-item list) · Unable to read or write to a drive · Trying to convert incompatible data types (e.g. converting the text "abc" into a number)

Let's return to the rectangle area program, now fully corrected of its logic error, and test it with an unusual input:

def calculate_area(length, width):
   if length < 0 or width < 0:
      raise ValueError("Length and width must be positive values.")
   area = length * width
   return area

def main():
   try:
      length = float(input("Enter the length of the rectangle: "))
      width = float(input("Enter the width of the rectangle: "))
      area = calculate_area(length, width)
      print(f"The area of the rectangle is approximately {area:.2f} square units.")
   except ValueError as error:
      print(f"Error: {error}")

main()
TestTest DataExpected OutcomeActual OutcomeChanges Needed?
1 Length = 10
Width = 10
"The area of the rectangle is approximately 100 square units." "The area of the rectangle is approximately 100.00 square units." N
2 Length = "abc"
Width = 0
"Program could not convert string to float, try again" Program crashed Y — should give an error message and ask the user to enter again

Test 2 reveals the runtime error. Typing "abc" where a number is expected causes float(input(...)) to raise an error that isn't a ValueError from the rectangle logic — it's a conversion error the try/except block wasn't built to catch and recover from repeatedly. The program crashes instead of asking the user to try again.

The fix The runtime error is identified as a missing iteration (missing loop) — the program doesn't ask the user to re-enter their input after a bad value, it just crashes. The fix wraps the whole input-and-calculate block inside a while True: loop, so that after an error, control returns to the top and asks again instead of ending the program.
while True:
   try:
      length = float(input("Enter the length of the rectangle: "))
      width = float(input("Enter the width of the rectangle: "))
      area = calculate_area(length, width)
      print(f"The area of the rectangle is approximately {area:.2f} square units.")
      break   # Exit the loop if successful
   except ValueError as error:
      print(f"Error: {error}")
      print("Please enter positive values for length and width.")

Notice the fix isn't a one-line tweak like the syntax and logic examples — sometimes a runtime error needs a structural change, like adding a loop so the program recovers gracefully instead of dying.

Practice Question 4.1

A program stores 5 students' marks in an array indexed 0 to 4, then this line runs:
print(marks[5])
What type of error is this, and why does it happen?

Practice Question 4.2

Explain, in your own words, why a runtime error is different from a syntax error even though both can stop a program.

💡 Exam Tip When asked to describe the effect of a runtime error, use the phrase "causes the program to crash". Also be ready to suggest a fix — often this means adding validation (checking input before using it) or exception handling (try/except).

5. Comparing All Three Error Types

This is the single most useful table in this whole chapter — if you can rebuild this from memory, you're set for any "identify the error type" question.

Feature Syntax Error Logic Error Runtime Error
Does the program run? No — never starts Yes — runs fully Starts, then stops partway
What goes wrong? Breaks language grammar rules Produces the wrong result Hits an unhandled situation
Exam phrase "Prevents the program from running" "Produces incorrect output" "Causes the program to crash"
How you find it Read the error message / check code carefully Trace tables, comparing expected vs actual output Test with unusual/edge-case inputs
Example Missing colon, misspelt keyword Using < instead of <= Dividing by zero, array index out of range
Practice Question 5.1

A program is supposed to calculate average = total / count. When a user enters no data at all, count stays 0 and the program crashes. Which error type is this, and how do you know?


6. Algorithmic Thinking & Writing Algorithms

What Is Algorithmic Thinking?

Algorithmic thinking is the process of creating step-by-step instructions in order to produce a solution to a problem. It's the skill that sits underneath every single line of code you'll ever write — before you can code a solution, you need to think it through as a precise sequence of steps.

Algorithmic thinking leans on two big ideas you've probably met before:

Decomposition — breaking a big, complicated problem down into smaller, manageable chunks.
Abstraction — stripping away irrelevant detail so you can focus on what actually matters for solving the problem.

Once every step has been identified through decomposition and abstraction, you can write a precise set of rules (an algorithm) that solves the problem reliably, every single time.

Real-world analogies A recipe is algorithmic thinking in action — if you follow it precisely, step by step, you get the desired outcome (a finished dish) every time.

A set of traffic lights shows how algorithmic thinking leads to automation — a fixed sequence of rules (red → red+amber → green → amber → red) runs the same way, indefinitely, without a human deciding each time.

How to Approach Writing an Algorithm in an Exam

Writing algorithms under exam pressure is genuinely one of the hardest parts of this course — not because the logic is impossible, but because it's easy to lose track of what you're doing halfway through. Here's a practical approach that examiners specifically recommend:

Step-by-step approach 1. Plan first, code second. Sketch a rough plan on scrap paper (or the back of the exam) before writing your actual answer.
2. Chunk the problem. Break your algorithm into labelled parts, e.g. "This part enters the grades," "this part calculates the total," "this part allocates the grade."
3. Order the chunks logically, then assemble the whole algorithm.
4. Use the exact variable names given in the question. This is a huge, easy-to-miss mark loser — if the question says the variable is called studentMark, don't rename it mark or score.
5. Comment your code. It helps the examiner follow your logic and often earns marks directly in the mark scheme.

A worked example of a plan for "read 30 students' marks, calculate their grade, and output a summary" might look like:

Part 1: Declare and initialise variables
Part 2: Loop to input marks for each subject
Part 3: Allocate grades for each student's subject
Part 4: Include a loop to repeat for all 30 students
Part 5: Output all necessary data
💡 Important Note Pseudocode doesn't have one fixed official syntax — it just needs to be clearly understandable. That said, sticking closely to the IGCSE pseudocode conventions (e.g. FOR...NEXT, IF...THEN...ENDIF, OUTPUT, INPUT) keeps your answer consistent and easy for examiners to mark.
Practice Question 6.1

Explain, using an example, the difference between decomposition and abstraction when applying algorithmic thinking to a problem.


7. What to Memorise

Syntax Error Breaks the grammar rules of the language. Stops the program from running at all. Exam phrase: "prevents the program from running."
Logic Error The program runs but gives the wrong output/result. Found using trace tables. Exam phrase: "produces incorrect output."
Runtime Error The program runs, then crashes when it hits a situation it can't handle. Exam phrase: "causes the program to crash."
Trace Table A table tracking the value of every variable line-by-line as a program runs, used to spot exactly where an error occurs.
Off-by-one Error A common logic error where a loop runs one time too many or too few, often due to incorrect comparison operators or array index confusion.
Algorithmic Thinking The process of creating step-by-step instructions to solve a problem, using abstraction and decomposition.
Decomposition Breaking a large, complex problem down into smaller, more manageable sub-problems.
Abstraction Removing irrelevant detail so you can focus on the parts of a problem that actually matter for the solution.

8. Concepts Checklist


9. Exam Tips & Common Mistakes

⚠️ Vague answers lose marks Never write "the program didn't work" or "there's a mistake." Examiners want you to (1) name the error type, (2) locate it — quote the exact line — and (3) explain the impact on the output or execution.
⚠️ Don't confuse crashing with wrong output A common mistake is calling a crash a "logic error." If the program stops running unexpectedly, that's a runtime error. A logic error means the program finishes running but the answer is wrong.
⚠️ Watch for array index confusion Students frequently forget that array/list indexing starts at 0, not 1. This causes both logic errors (off-by-one mistakes in loops) and runtime errors (index out of range).
⚠️ Use exact variable names from the question When writing or amending algorithms, always use the precise variable names given in the question. Renaming them, even to something sensible, loses marks.
⚠️ Trace tables need every variable, every line When drawing a trace table, don't skip lines or variables just because they "obviously" haven't changed — mark schemes check for completeness, and skipping a step is exactly where you'll miss spotting the error.

What Examiners Are Really Looking For

  • Correct identification of the error type using the correct terminology
  • Precise location of the error (the exact line or expression)
  • A clear explanation of the impact on the program's behaviour or output
  • A working, testable fix — not just "add code here"
  • Use of proper trace table structure when tracing variables
  • Algorithms that use the exact variable names and data given in the question
🔓 Read the full Identifying Errors note — free You're seeing the preview · free account, no card needed
Also in the full note
  • 6. Algorithmic Thinking & Writing Algorithms
  • 9. Exam Tips & Common Mistakes
What's inside
📖 Revision notes 🎯 Learn mode ✦ AI flashcards ✓ Instant AI marking 🧊 3D explorers 🧪 Experiments & simulations 📈 Progress tracking
📄 Practise Identifying Errors with Computer Science 0478 past papers Every paper with its mark scheme — answer online, marked instantly. Open →

Read the full Identifying Errors notes free

That's the preview — create a free account to read the rest, plus flashcards and practice questions with instant AI marking. No credit card.

Unlock the full notes free →

More Computer Science topics