Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
OCR GCSE Computer Science (Paper 2) Smart practice A mixed round aimed at your weak spots
Unit 1
Algorithms
Unit 2
Programming fundamentals
Unit 3
Producing robust programs
Unit 4
Boolean logic
Unit 5
Programming languages and IDEs
Unit 6
Practical programming (Section B)
Avg
score:
–
Topics
done:
0/31

Sequence and selection

Practise 31 exam-style questions on Sequence and selection for OCR GCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with the Study Helper on hand if you get stuck.

  • 31 questions
  • 1–6 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

2 marks

Describe what is meant by selection in a program.

Model answer

Selection is when the program tests a condition, and the result (True or False) decides which block of code is run next, so some code may be skipped. In OCR Exam Reference Language it is written with if ... then ... else ... endif or switch ... case.

Explanation

Selection lets a program make decisions. A condition such as age >= 18 is evaluated, and the program follows one branch if it is True and another (or none) if it is False. Selection does not repeat code - that is iteration - and code in a branch that is not chosen does not run at all.

Mark scheme
  1. 1 mark

    a condition is tested / evaluated (as True or False)

    Accept 'a decision is made using a Boolean expression'.

  2. 1 mark

    the result decides which block of code / path is run (and other code is skipped)

    Accept 'the program branches'. An example such as if ... then ... else on its own scores 1 mark at most.

Question 2

3 marks

Look at this program.

mark = int(input("Enter mark"))
if mark >= 70 then
    print("Distinction")
elseif mark >= 50 then
    print("Merit")
elseif mark >= 30 then
    print("Pass")
else
    print("Fail")
endif

State the output when the user enters each of these marks: 70, 50 and 29.

Model answer

70: Distinction (70 >= 70 is True)
50: Merit (50 >= 70 is False, 50 >= 50 is True)
29: Fail (all three conditions are False)

Explanation

The conditions are tested in order from the top, and the first one that is True decides the output; the rest are skipped. >= includes the boundary, so 70 gives Distinction and 50 gives Merit. 29 is below 30, so every condition is False and the else branch runs.

Mark scheme
  1. 1 mark

    70: Distinction

    Correct outputs with no working score the marks.

  2. 1 mark

    50: Merit

    Do not accept 'Merit and Pass': only one branch runs.

  3. 1 mark

    29: Fail

Question 3

3 marks

This program should tell the user whether a temperature is below, at or above freezing point. It contains three errors.

01temp = int(input("Enter temperature"))
02if temp = 0 then
03    print("Freezing point")
04elseif temp < 0
05    print("Below freezing")
06else
07    print("Above freezing")

Identify the three errors and state how to correct each one.

Model answer

Line 02: = is assignment; it should be == for a comparison: if temp == 0 then
Line 04: the keyword then is missing: elseif temp < 0 then
After line 07: endif is missing, so the selection is never closed.

Explanation

In OCR Exam Reference Language every if and elseif condition ends with then, comparisons for equality use ==, and every if statement must be closed with endif. These are all syntax errors: the program would not run until they are fixed. Indentation alone does not close an if statement in ERL.

Mark scheme
  1. 1 mark

    line 02: = should be == (comparison, not assignment)

    The error and its correction are both needed for each mark. Accept the corrected line, e.g. if temp == 0 then.

  2. 1 mark

    line 04: then is missing / elseif temp < 0 then

  3. 1 mark

    endif is missing (after line 07 / at the end)

    Accept 'the if statement is not closed'.

Question 4

5 marks

The flowchart below shows an algorithm used by a car park to work out the charge, in pounds, for parking. The number of hours is a whole number.

Write this algorithm using OCR Exam Reference Language or a high-level programming language.

Flowchart, read from the top. START, then the input/output box "input hours", then the decision box "hours <= 2?" (if Yes, the process box "charge = 0"; if No, the process box "charge = (hours - 2) * 3"; the two paths then join). After the paths join: the input/output box "print(charge)", then STOP.

Model answer

hours = int(input("Enter the number of hours parked"))
if hours <= 2 then
    charge = 0
else
    charge = (hours - 2) * 3
endif
print(charge)

Explanation

The decision box becomes an if ... else: the Yes branch sets charge to 0 and the No branch calculates it. The brackets matter, because without them 2 * 3 would be worked out first. For example, 5 hours costs (5 - 2) × 3 = £9, while 2 hours is free. The output box comes after the two branches rejoin, so print goes after endif.

Mark scheme
  1. 1 mark

    inputs hours

    Answers must be in OCR Exam Reference Language or a high-level programming language (e.g. Python); pseudocode, natural English or bullet points score 0. Ignore minor syntax errors. Do not penalise a missing int() conversion.

  2. 1 mark

    if hours <= 2 then

    Accept hours < 3, or hours > 2 with the two branches the other way round.

  3. 1 mark

    charge = 0 when the condition is True

  4. 1 mark

    else charge = (hours - 2) * 3

    Brackets are needed: hours - 2 * 3 is wrong. Accept charge = hours * 3 - 6.

  5. 1 mark

    outputs charge after the selection (for both branches)

    Accept a print in each branch.

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

Study Helper Hints first, answers after you try

Stuck on this one? Ask for a hint and I’ll point you in the right direction, without giving the answer away. Once you’ve checked your answer, I’ll show you how the marks are awarded.