OCR GCSE Computer Science June 2024 Paper 2, Question 9(b): the javelin trace table
OCR J277/02 June 2024, Question 9(b): trace an if, elseif, else algorithm that scores a javelin throw of 14.3 by a year 10 student. Which lines run, the four marks explained, and the algorithm to run with other throws.
Question 9(b) of the OCR GCSE Computer Science Paper 2 sat on 21 May 2024 (J277/02) is a 4 mark trace table with no loop in it. The skill is knowing which lines of an if ... elseif ... else run, and which are skipped.
We do not copy the exam paper here. Open it beside this page: OCR June 2024 J277/02 question paper (PDF). When you have finished, check the mark scheme too.
The question in short
The algorithm reads a javelin distance (line 01) and a year group (line 02). Then:
- a throw of 20.0 or more scores 3 (line 04);
- else a throw of 10.0 or more scores 2 (line 06);
- else the score is 1 (line 08);
- if the year group is not 11, the score is doubled (line 11);
- line 13 prints "The score is" and the score.
Trace it for a year 10 student who throws 14.3.
Work it through
Lines 01 and 02. javelinThrow is 14.3 and yearGroup is 10.
Line 03. Is 14.3 at least 20.0? No. Line 04 is skipped.
Line 05. Is 14.3 at least 10.0? Yes. So line 06 runs: score is 2. The else on lines 07 and 08 is skipped, because a branch has already been taken.
Line 10. Is 10 not equal to 11? Yes. So line 11 runs: score is 2 x 2 = 4.
Line 13. The output is The score is 4.
The finished trace table
| Line number | javelinThrow | yearGroup | score | Output |
|---|---|---|---|---|
| 01 | 14.3 | |||
| 02 | 10 | |||
| 06 | 2 | |||
| 11 | 4 | |||
| 13 | The score is 4 |
One mark for the two inputs on lines 01 and 02, one for the 2 on line 06, one for the 4 on line 11, and one for the output on line 13 with no other outputs. You may add rows for the lines where nothing changes, but you do not need to.
Where the marks are lost
- Score 1 as well as score 2. Only one branch of an
if ... elseif ... elseruns. Once line 06 has run, line 08 cannot. - Misreading
!=. It means "not equal to". The student is in year 10, which is not 11, so the score is doubled. The students who are not doubled are the year 11s. The score is, 4. The comma in theprintseparates two things to output. It is not printed.- Putting the score on line 05. Line 05 is the test. The assignment is on line 06. A wrong line number is penalised.
- Anything in the Output column that is not output. The mark scheme treats a dash or a 0 there as an output.
Run it
The algorithm in Python, printing the line number each time something changes. Change the two values at the top and trace it yourself first.
The program
from bugbot import *
connect()
# change these and press Run
THROW = 14.3
YEAR = 10
javelinThrow = THROW
print("01 javelinThrow =", javelinThrow)
yearGroup = YEAR
print("02 yearGroup =", yearGroup)
if javelinThrow >= 20.0:
score = 3
print("04 score =", score)
elif javelinThrow >= 10.0:
score = 2
print("06 score =", score)
else:
score = 1
print("08 score =", score)
if yearGroup != 11:
score = score * 2
print("11 score =", score)
print("13 The score is", score)
forward(60, distance=javelinThrow)
Questions
What is the answer to OCR J277 June 2024 Paper 2 Question 9(b)?
Line 01 sets javelinThrow to 14.3, line 02 sets yearGroup to 10, line 06 sets score to 2, line 11 sets score to 4, and line 13 outputs The score is 4.
How do I trace an if elseif else statement?
Test the conditions in order from the top. Run the block under the first one that is true, then jump to the endif. Every other block is skipped, even if its condition would also have been true.
Do I need a row for every line in an OCR trace table?
No. You need a row whenever a variable changes or something is output, with the correct line number. Rows for lines where nothing changes are allowed but not needed.
More from this paper
- Question 2: Complete a flowchart that decides odd or even with MOD 4 marks
- Question 3(a), (b): Define a syntax error, then correct two logic errors in a range check 6 marks
- Question 3(c): Show a binary search for 10, its pre-requisite, and name merge sort 5 marks
- Question 5: A truth table for (A AND B) OR C and a circuit for NOT A AND (B OR C) 7 marks
- Question 6: String methods: upper, left, right with a cast, and concatenation 6 marks
Every OCR J277 question we have worked · Guide: Logic gates and truth tables explained
Learn it step by step
- F13.2 Trace tables Exam preparation
- F2.3 else, elif and Boolean operators Decisions and loops
- 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.