OCR GCSE Computer Science Paper 2, June 2025: question 4

A PrepWise guide to a real paper, with our descriptions and answers. Not made or approved by OCR.

PrepWise guide: OCR GCSE Computer Science Paper 2Question 44 of 6

A program works through the text file data.txt one number at a time and shows a number only when it is anything other than 0. Figure 6 is the program with five gaps.

Figure 6
An algorithm of eight lines with five gaps marked by numbered black circles.Open full size to read the labels (Figure 6, opens in a new tab)
04.1[5 marks]

Complete Figure 6 by choosing OCR Exam Reference Language statements from the box for gaps 1 to 5. Not every word is used.

See how you would score on File Handling

Our own questions on this topic, marked straight away, so you see what to revise. Free now.

data
for
if
myFile.close()
myFile.readLine()
input()
myFile.writeLine()
open
print
temp
txt
x
Show model answer for 04.1Hide model answer for 04.1
myFile = open("data.txt")
while NOT myFile.endOfFile()
    temp = myFile.readLine()
    if int(temp) != 0
        print(temp)
    endif
endwhile
myFile.close()
Gap 1: open
Gap 2: myFile.readLine()
Gap 3: temp
Gap 4: print
Gap 5: myFile.close()
5 marks

How the marks are earned

  1. One mark for each gap, up to 5. Only one choice per gap: a gap with several options chosen earns nothing.
  2. BP1, gap 1: open.
  3. BP2, gap 2: myFile.readLine(). The form readLine is credited.
  4. BP3, gap 3: temp. The choice myFile.readLine() is credited here only if it was not used in gap 2.
  5. BP4, gap 4: print.
  6. BP5, gap 5: myFile.close(). The form close is credited.
  7. Spelling slips, capital letters and minor differences are ignored as long as it is clear which option was chosen.

Why it scores

open opens the file for reading. Each pass of the loop reads one line into temp, tests it as a number, and prints it only if it is not 0. close finishes with the file once the loop ends.

The five answers in gap order. Words such as data, txt, x and input() are the unused ones.

Revise File Handling
04.2[1 mark]

Identify how this algorithm uses casting.

See how you would score on Data Types
Show model answer for 04.2Hide model answer for 04.2

int(temp) converts the text read from the file into an integer, so it can be compared with 0.

1 mark

How the marks are earned

  1. It converts the data to an integer (to int).
  2. A vague answer such as changes it to a different data type earns nothing.
Revise Data Types
OCR owns the copyright in its exam questions, so we cannot copy their wording. These descriptions and answers are ours. Not made or approved by OCR.[6 marks]