OCR GCSE Computer Science June 2025 Paper 2, Question 6(d): tracing and refining an array total
OCR J277/02 June 2025, Question 6(d): complete the trace table for a for loop that adds up 10, 14 and 6 from an array, change the loop for an array of five, and refine the print line to output a message. Worked through, with the algorithm to run.
Question 6(d) of the OCR GCSE Computer Science Paper 2 sat on 20 May 2025 (J277/02) uses one five line algorithm three ways. Trace it (4 marks), change it for a longer array (2 marks), and improve its output (1 mark).
We do not copy the exam paper here. Open it beside this page: OCR June 2025 J277/02 question paper (PDF). When you have finished, check the mark scheme too.
The question in short
An array, actNumbers, holds the number of acts on each of three stages: 10, 14 and 6, at index 0, 1 and 2.
Line 01 sets count to 0. Line 02 starts a for loop with x from 0 to 2. Line 03 adds actNumbers[x] to count. Line 04 is next x. Line 05 prints count.
Part (i): the trace table
| Line number | count | x | Output |
|---|---|---|---|
| 01 | 0 | ||
| 02 | 0 | ||
| 03 | 10 | ||
| 02 | 1 | ||
| 03 | 24 | ||
| 02 | 2 | ||
| 03 | 30 | ||
| 05 | 30 |
The four marks: count starting at 0; count going to 10, 24, 30 and nothing else; x going 0, 1, 2; and 30 as the only output.
Line numbers are not needed for the marks on this one. The order of the values down each column is what counts. (If you show x reaching 3 as the loop ends, that is allowed too.)
Part (ii): two more stages
The array now has five items, at index 0 to 4. Only the loop has to change:
- Line 02
for x = 0 to 4
for x = 0 to actNumbers.length - 1 is accepted too, and is better code: it never needs changing again.
Part (iii): a better output
print("The total act count is " + count)
Any separator is accepted, including a comma, and casting with str(count) is ignored. In Python, print("The total act count is", count) does it.
Where the marks are lost
- Adding the index and not the value.
count + actNumbers[x]adds what is stored at position x: 10, not 0. - Writing
print(30)in the Output column. The output is30. for x = 0 to 5thought of as five. In OCR's reference language the end value is included, so 0 to 4 is five passes. (The mark scheme lets 0 to 5 go for Python thinkers, but 0 to 4 is right.)- Changing line 03. Nothing in it depends on the size of the array.
- No space before the closing quote in part (iii). Without it the output is "...count is50". The mark scheme ignores spacing, but real users will not.
Run it
The algorithm in Python, printing the line number at each change. STAGES switches between the two arrays. The robot drives 1 cm for every act.
The program
from bugbot import *
connect()
# 3 is the array in part (i). 5 is the array in part (ii)
STAGES = 3
actNumbers = [10, 14, 6, 9, 11][:STAGES]
count = 0
print("01 count =", count)
for x in range(0, len(actNumbers)):
print("02 x =", x)
count = count + actNumbers[x]
print("03 count =", count)
print("05 The total act count is", count)
forward(60, distance=count)
Questions
What is the answer to OCR J277 June 2025 Paper 2 Question 6(d)(i)?
count goes 0, 10, 24, 30. x goes 0, 1, 2. The output is 30.
How should the loop change for an array of five items?
Line 02 becomes for x = 0 to 4, so that x visits every index from 0 to 4.
How do I output text and a variable together?
Concatenate them: print("The total act count is " + str(count)). In Python you can also separate them with a comma inside print.
More from this paper
- Question 1: Normal, boundary and invalid test data, and a 1 to 100 range check 9 marks
- Question 2(a), (b): Count the passes of a flowchart loop, and describe the kinds of iteration 8 marks
- Question 3(a): Show the steps of a merge sort on eight numbers 4 marks
- Question 4: Complete an algorithm that reads numbers from a text file, and casting 6 marks
- Question 5(a), (b): A logic circuit from a description, and the truth table for A AND B 5 marks
Every OCR J277 question we have worked · Guide: Trace tables explained
Learn it step by step
- F13.2 Trace tables Exam preparation
- F3.4 Iterating over a list Strings, lists and records
- F5.4 Trace tables Algorithms
This is our own explanation of a published exam question. It is not written or endorsed by OCR, and the question paper and mark scheme remain OCR's copyright. Read them on OCR's site with the links on this page.