OCR GCSE Computer Science June 2023 Paper 2, Question 6(c): reading a program
OCR J277/02 June 2023, Question 6(c): read a six line program and find the concatenation, a variable, a function call, the data type a function returns and the programming constructs used. Each answer explained, with the program to run.
Question 6(c) of the OCR GCSE Computer Science Paper 2 sat on 25 May 2023 (J277/02) gives you six lines of code and five short parts worth 6 marks. Nothing has to be written or traced. You have to know the vocabulary: concatenation, identifier, function call, data type, construct.
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.
The question in short
The program resets a sensor on an alarm system:
- line 01 asks the user for the code of a type of sensor and stores it in
sensorType; - line 02 is an
ifthat calls a pre-written function,CheckSensorCode(sensorType), to see whether the code is valid; - line 03 asks for the number of the sensor and stores it in
sensorNumber; - line 04 sets
sensorIDtosensorType + sensorNumber; - line 05 calls
ResetSensor(sensorID); - line 06 ends the
if.
The five parts
(i) The line with concatenation: line 04. Both inputs are strings, so + joins them end to end. "DS" and "3" make "DS3".
(ii) The identifier of a variable: sensorType, sensorNumber or sensorID. Any one. An identifier is just a name. CheckSensorCode and ResetSensor are identifiers too, but they name subprograms, not variables.
(iii) The data type returned by CheckSensorCode(): Boolean. Look at how it is used. It sits alone as the condition of an if, with no comparison after it. A condition has to be True or False, so that is what the function gives back.
(iv) A line with a function call: line 01, 02, 03 or 05. input() is a function call as well, which is why lines 01 and 03 count. The only working line without a call is line 04.
(v) Two programming constructs: sequence and selection. Sequence is the lines running in order. Selection is the if. There is no loop, so iteration is wrong.
Where the marks are lost
- "
if" for part (v). The question asks for the construct, and the mark scheme refuses examples. The construct is called selection. - "String" for part (iii). The function takes a string in. What comes out is a Boolean.
- Iteration in part (v). Do not write all three constructs from memory. Check the code: nothing repeats.
- Line 02 for concatenation. Brackets after a name mean a call, not a join.
Run it
The program in Python, with simple versions of the two pre-written subprograms so that it can run. It prints the type of what CheckSensorCode returns.
The program
from bugbot import *
connect()
def CheckSensorCode(code):
return code == "MS" or code == "DS" or code == "WS"
def ResetSensor(sensorID):
led("green")
print("Sensor", sensorID, "has been reset")
sensorType = input("Enter code of the type of sensor to reset: ")
print("CheckSensorCode returned", CheckSensorCode(sensorType), "which is a", type(CheckSensorCode(sensorType)).__name__)
if CheckSensorCode(sensorType):
sensorNumber = input("Please input the number of the sensor to reset: ")
sensorID = sensorType + sensorNumber
ResetSensor(sensorID)
Questions
What are the answers to OCR J277 June 2023 Paper 2 Question 6(c)?
(i) Line 04. (ii) sensorType, sensorNumber or sensorID. (iii) Boolean. (iv) Line 01, 02, 03 or 05. (v) Sequence and selection.
What are the three programming constructs?
Sequence (instructions carried out in order), selection (choosing a path with if or a case statement) and iteration (repeating with a for, while or do until loop).
How can I tell what data type a function returns?
Look at how its result is used. If the call is the whole condition of an if or a while, it returns a Boolean. If the result is used in arithmetic it is a number, and if it is joined to text it is a string.
More from this paper
- Question 1(b) to (d): An assignment, the arithmetic operators, and a do until trace table 7 marks
- Question 2: Syntax and logic errors: correct a loop that should total an array 6 marks
- Question 3: Insertion sort: temp, the inner loop, and bubble sort compared 8 marks
- Question 5(c): An adding game: three random questions and a score 6 marks
- Question 6(b): Sound an alarm when armed AND (door OR window) 4 marks
Every OCR J277 question we have worked
Learn it step by step
- F3.1 String handling Strings, lists and records
- F4.2 Parameters and return values Functions and structured code
- F1.3 Calling functions Programming basics
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.