8.2 - Programming Errors
There are a number of different errors that can occur when programming.
A syntax error is a mistake in the rules or grammar of the program so the program cannot be converted into an executable form (can't be compiled).
E.g. 'Print' in Python should be 'print'
number / 0
An execution (or runtime) error is when the program unexpectedly stops as a result of an operation during execution.
E.g. Attempting to read line 8 in a file with only 7 lines or attempting to divide by zero.
A logical error is a mistake in the program instructing the program to do the wrong thing so the program works but produces the wrong output.
E.g. Total = Price – VAT instead of E.g. Total = Price + VAT
A linking error occurs when a compiler can’t find the sub procedure as the programmer might have declared it incorrectly / did not instruct the compiler to include the sub program (library) in the code.
name = "jef"
A rounding error is when the program rounds a real number to a fixed number of decimal places resulting in losing some information as the number becomes less accurate.
E.g. 3.125 rounding to 3.13
A truncation error is when the program truncates a real number to a fixed number of decimal places resulting in losing some information as the number becomes less accurate.
E.g. 3.125 truncating to 3.12
For each of the scenarios below state the error that will occur.
1. A command word (such as for or print) has been misspelled.
2. The average speed is 120.3856 but only 120.3 is displayed.
3. The cost of a meal is £40 but £42 is displayed.
4. A program uses a subroutine that has not been imported.
5. The height of a dog is 33.38cm but 33.4cm is displayed.
6. The user wants to read line 9 of a file that only has 6 lines.
7. The user's age is printed instead of their name.
8. The programmer has typed print("hello"(
9. A number is divided by 0.
10. The program is asked to generate a random number but 'import random' has not be written.