Question 1 Report
Errors in programs can be classified into different types.
| Error type | Description | Example |
|---|---|---|
| Syntax error | ||
| Logic error | ||
| Runtime error |
(a) Complete the table by describing each type of error and giving an example. [6]
(b) State which type of error is typically the hardest to find. Explain why. [2]
(a)
| Error type | Description | Example |
|---|---|---|
| Syntax error | A mistake in the code that violates the grammar rules of the programming language, preventing the program from being compiled or interpreted. [1] | Writing pritn("Hello") instead of print("Hello"), or forgetting to close a bracket. [1] |
| Logic error | The program runs without crashing but produces incorrect results because the algorithm or reasoning in the code is wrong. [1] | Using + instead of - in a calculation, so the program adds when it should subtract. [1] |
| Runtime error | An error that occurs while the program is running, causing it to crash or stop unexpectedly. [1] | Attempting to divide a number by zero, or trying to open a file that does not exist. [1] |
(b) Logic errors are typically the hardest to find. [1] The program runs without any error messages, so the programmer receives no automatic indication of where the problem is. They must trace through the code manually or use debugging tools to identify the exact point where the output deviates from the expected behaviour. [1]
Everything you need to excel in your exams