10.3: Programming Errors

Exam Board:

Eduqas / WJEC

Specification:

2020 + 

Syntax Error

A syntax error is a mistake in the grammar or spelling of the program.

A syntax error will prevent the program from being compiled.

Examples: 

Incorrect Spelling:

pront ("hello")

Incorrect punctuation:

print ("hello"(

Execution (Runtime) Error

An execution error is when the program unexpectedly stops as a result of an operation during execution.

Examples: 

Dividing by zero:

400 / 0

Reading too far in a file:

#There are 50 lines in the file

line = file.readlines( )

print ( line [100] )

Logical Error

Linking Error

A logical error is a mistake made by the programmer - the program still works but displays the wrong output.

Examples: 

Truncation Error

Rounding Error

A linking error occurs when a compiler can’t find a sub procedure (e.g. the random library in Python) that has been used.

 

The programmer might have declared it incorrectly or forgotten to link (import) it.

Examples: 

Spelling an import command incorrectly:

import ramdon

number = random.randint(1,10)

Requesting a function without linking:

number = random.randint(1,10)

Incorrect calculation:

total = num1 - num2

print (total)

Incorrect variable printed:

age = 16

name = "Steve"

print ("Nice to meet you" , age)

A rounding error is when the program rounds a real number to a fixed number of decimal places.

 

This results in losing some value as the number becomes less accurate.

Examples: 

Rounding up:

80.87 = 80.9 (Inaccurate by 0.03)

Rounding down:

63.4 = 63 (Inaccurate by 0.4)

A truncation error is when the program truncates a real number to a fixed number of decimal places.

 

This results in losing some value as the number becomes less accurate.

Examples: 

Truncation to 2 decimal places:

92.13787 = 92.13 (Inaccurate by 0.00787)

Truncation to 1 decimal place:

25.199876 = 25.1 (Inaccurate by 0.099876)

Questo's Questions

10.3 - Programming Errors:

1. Describe and give an example of each type of error:

  • a. Syntax Error [3]

  • b. Execution (Runtime) Error [3]

  • c. Logical Error [3]

  • d. Linking Error [3]

  • e. Rounding Error [3]

  • f. Truncation Error [3]

2. State the error that will occur for each scenario:   [1 each]

  • a. A command word (such as for or print) has been misspelt.

  • b. The average speed is 120.3856 but only 120.3 is displayed.

  • c. The cost of a meal is £47 but £40 is displayed.

  • d. A program uses a subroutine that has not been imported.

  • e. The height of a dog is 33.38cm but 33.4cm is displayed.

  • f. The user wants to read line 9 of a file that only has 6 lines.

  • g. The user's age is printed instead of their name.

  • h. The programmer has typed print("hello"(

  • i. A number is divided by 0.

  • j. The program is asked to generate a random number but 'import random' has not be written.

© CSNewbs 2020