OCR GCSE Computer Science June 2023 Paper 2, Question 1: operators and a do until trace table

OCR J277/02 June 2023, Question 1(b) to (d): write an assignment, choose the arithmetic operators for power, remainder and difference, and trace a do until loop line by line. Worked through, with the algorithm to run.

Past paper questionOCR J277/02June 2023 Paper 27 marksTrace table

Question 1 of the OCR GCSE Computer Science Paper 2 sat on 25 May 2023 (J277/02, Computational thinking, algorithms and programming) has four parts. Part (a) is a tick box table about high-level and low-level languages. This page works through parts (b), (c) and (d), which are about code: 7 marks between them.

We do not copy the exam paper here. Open it beside this page: OCR June 2023 J277/02 question paper (PDF). When you have finished, check the mark scheme too.

Part (b): add two variables (1 mark)

num1 and num2 hold integers. Write pseudocode that adds them and stores the result in total.

total = num1 + num2

The variable being given a value goes on the left. num1 + num2 = total is the wrong way round.

Part (c): the missing arithmetic operators (3 marks)

Three short algorithms each have one operator missing.

Purpose Operator Python
12 to the power of 2 ^ **
Is a number odd or even? MOD %
The difference between two measurements - -

MOD gives the remainder after a division. A number MOD 2 is 0 when the number is even. OCR's other division operator, DIV, gives the whole number part, and it is the usual wrong answer here.

The mark scheme accepts the Python symbols, ** and %, as well as OCR's own.

Part (d): trace the do until loop (3 marks)

The algorithm sets start to 3. Then it repeats two lines, printing start and taking 1 off it, until start equals -1. Last, it prints "Finished".

OCR's trace tables have a line number column. Write a new row each time a line changes a variable or outputs something.

Line number start Output
01 3
03 3
04 2
03 2
04 1
03 1
04 0
03 0
04 -1
06 Finished

The three marks are for: setting start to 3 on line 01 and outputting 3 on line 03; then 2, 1 and 0 output with start going down to -1 on the right lines; and "Finished" on line 06.

Lines 02 and 05 (do and until) change nothing and output nothing, so they do not need rows.

Where the marks are lost

  • Outputting -1. When start becomes -1 the until condition is true, so the loop ends before line 03 runs again. The mark scheme says -1 must not be output.
  • Stopping at 1. 0 is not -1, so the loop goes round again and 0 is output.
  • Wrong line numbers. The print is on line 03 and the subtraction is on line 04. Putting both on one row is penalised.
  • Writing sums in the table. 3 - 1 is not a value. Write 2.
  • Forgetting "Finished". A whole mark for one word.

Run it

Python has no do ... until. The usual way to write one is while True with a break at the bottom. This version prints the line number with each change, so it reproduces the trace table. The robot drives start centimetres on each pass, which is why the last pass does not move it.

It prints the ten rows of the trace table. Change START to 5 and predict how many rows there will be before you run it.
The program
from bugbot import *
connect()

# change START and press Run
START = 3

start = START
print("01 start =", start)
while True:
    print("03 output", start)
    if start > 0:
        forward(60, distance=start)
    start = start - 1
    print("04 start =", start)
    if start == -1:
        break
print("06 output Finished")

print(12 ** 2, 53 % 2, 300 - 100)
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What is the answer to OCR J277 June 2023 Paper 2 Question 1(d)?

Line 01 sets start to 3. Then lines 03 and 04 repeat: 3 is output and start becomes 2, 2 is output and start becomes 1, 1 is output and start becomes 0, 0 is output and start becomes -1. The loop ends and line 06 outputs Finished.

What are the arithmetic operators in OCR Exam Reference Language?

Plus, minus, * for multiply, / for divide, ^ for power, MOD for remainder and DIV for whole number division.

What is the difference between a do until loop and a while loop?

A do until loop checks its condition at the end, so its body always runs at least once. A while loop checks at the start, so its body may never run.

More from this paper

Every OCR J277 question we have worked · Guide: Trace tables explained

Learn it step by step

  1. F1.9 Arithmetic operators Programming basics
  2. F5.4 Trace tables Algorithms
  3. F13.2 Trace tables Exam preparation
Open the lessons

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.