Chhetri AcademyGCSE & A level Paper Builder

Trace tables and common errors

OCR GCSE Computer Science (J277) · Algorithms and programming (Paper 2) › Algorithms › Designing, creating and refining algorithms

Practise Trace tables and common errors. 11 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.

Build a paper on this topic

▶ Watch videos on Trace tables and common errors (Craig 'n' Dave OCR on YouTube) · Practise all of Designing, creating and refining algorithms

Sample questions

Written for this site in the style of OCR exam questions. They are not taken from real past papers.

Question 1Easy6 marks
(a) State what is meant by a syntax error.[1]
(b) State what is meant by a logic error.[1]
(c) Complete {table} by stating whether each error is a syntax error or a logic error.[4]
[object Object]
Show the answer and mark scheme
(a)
  • an error that breaks the rules / grammar of the programming language (so the code cannot be translated / run)
(b)
  • an error that means the program runs but does not do what it should / gives an unexpected or incorrect output
(c)
  • syntax
  • logic
  • syntax
  • logic
Question 2Medium6 marks
This algorithm should output the largest of three numbers. It contains a logic error.
01 a = int(input("First number"))
02 b = int(input("Second number"))
03 c = int(input("Third number"))
04 largest = a
05 if b > largest then
06    largest = b
07 endif
08 if c > a then
09    largest = c
10 endif
11 print(largest)
(a) Give a set of three inputs that would produce an incorrect output. State the output the algorithm would give for your inputs.[2]
(b) Identify the line that contains the logic error and write the corrected line.[2]
(c) Explain whether this error would be reported when the program is translated.[2]
Show the answer and mark scheme
(a)
  • any inputs where b is the largest and c is between a and b (b > c > a), e.g. a = 1, b = 9, c = 5
  • the output for those inputs, e.g. 5 (instead of 9)
(b)
  • line 08
  • if c > largest then
(c)
  • no, it would not be reported
  • the code does not break the rules of the language / is syntactically correct, so it translates and runs but gives the wrong result
Question 3Hard7 marks
This program should output the mean average of the scores in an array. It contains one syntax error and two logic errors.
01 scores = [12, 18, 9, 15, 10]
02 total = 0
03 for i = 1 to scores.length
04    total = total + scores[i]
05 next i
06 average = total DIV scores.length
07 print("Average: " + str(average)
(a) Identify the line that contains the syntax error and write the corrected line.[2]
(b) Line 03 contains a logic error. Explain the effect of this error and write the corrected line.[3]
(c) Assume that the error in line 03 has been corrected. Line 06 also contains a logic error.
State the value that line 06 would give for average, and write the corrected line.[2]
Show the answer and mark scheme
(a)
  • line 07
  • print("Average: " + str(average)) (closing bracket added)
(b)
  • arrays are indexed from 0, so scores[0] / the first score (12) is never added
  • the loop tries to use scores[5], which does not exist / index out of range (error)
  • for i = 0 to scores.length - 1
(c)
  • 12 (instead of 12.8)
  • average = total / scores.length

Related subtopics

Stuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.

Book a free trial