Question bank › GCSE › GCSE Computer Science › Programming fundamentals

Programming fundamentals: variables, operators, sequence, selection, iteration

10 questions42 marksabout 50 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 4–54 marks

(a) State the result of each expression.

(i) 17 MOD 5 [1]

(ii) 17 DIV 5 [1]

(iii) 2 ^ 4 [1]

(b) The code below uses iteration.

do
    pin = input("Enter PIN")
until pin == "4821"

State the type of iteration used. [1]

2Grade 1–34 marks

A program for a school tuck shop is shown below.

01 const VAT = 0.2
02 name = input("Enter item name")
03 cost = float(input("Enter cost"))
04 total = cost * (1 + VAT)
05 print(name + " costs " + str(total))

(a) Give the line number of a line that contains an assignment to a variable using an arithmetic operator. [1]

(b) VAT is declared as a constant. Explain one difference between a constant and a variable. [1]

(c) Identify one line that performs an input and one line that performs an output. [2]

3Grade 4–54 marks

The algorithm below is written in OCR Exam Reference Language.

total = 0
for i = 1 to 4
    total = total + i * i
next i
print(total)

(a) Complete the trace table for this algorithm. [3]

itotal
0
11

(b) State the type of iteration used in this algorithm. [1]

Stuck on Programming fundamentals: variables, operators, sequence, selection, iteration?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 4–54 marks

A program contains the variables x = 8 and y = 3.

State whether each of the following expressions evaluates to True or False.

(a) x > y AND y != 3 [1]

(b) x MOD y == 2 OR y > x [1]

(c) NOT (x <= y) [1]

(d) (x > 5 AND y > 5) OR x == 8 [1]

5Grade 4–54 marks

A cinema charges for tickets using the following rules:

  • under 5 years old: free
  • 5 to 15 years old: £4
  • 65 years old or over: £5
  • everyone else: £9

Part of the program is shown below.

age = int(input("Enter age"))
if age < 5 then
    price = 0
elseif age < 16 then
    price = 4
elseif age >= 65 then
    price = 5
else
    price = 9
endif
print(price)

(a) State the output when the user enters 16. [1]

(b) State the output when the user enters 65. [1]

(c) The programmer swaps the order of the first two conditions so that age < 16 is tested first and age < 5 second. Explain the effect this has on the output for a user aged 4. [2]

6Grade 6–74 marks

The following program is written in OCR Exam Reference Language.

n = 10
i = 1
sum = 0
while i <= n
    sum = sum + i
    i = i + 2
endwhile
print(sum)

(a) State the value output by the program. [1]

(b) Rewrite the loop as a count-controlled loop that produces the same output. [3]

7Grade 6–74 marks

A program asks the user to enter a score between 1 and 10 inclusive. It must keep asking until a valid score is entered, then output "Score accepted".

Write an algorithm, using OCR Exam Reference Language or a high-level programming language, to do this. You must use a condition-controlled loop. [4]

8Grade 8–94 marks

The following algorithm uses nested iteration.

for i = 1 to 3
    for j = 1 to 3
        if (i + j) MOD 2 == 0 then
            print(i * j)
        endif
    next j
next i

(a) State how many times the line if (i + j) MOD 2 == 0 then is executed. [1]

(b) State the values output by the algorithm, in order. [2]

(c) The programmer changes the condition to (i + j) MOD 2 == 1. State how many values are now output. [1]

9Grade 4–54 marks

A programmer is writing two parts of a game.

  • Part A displays a countdown from 10 to 1 before the game starts.
  • Part B repeatedly asks the player to guess a number until the guess is correct.

(a) State which type of iteration is most suitable for Part A and justify your choice. [2]

(b) State which type of iteration is most suitable for Part B and justify your choice. [2]

10Grade 8–96 marks

A program is needed that:

  • repeatedly asks the user to enter a whole number, stopping when -1 is entered
  • counts how many of the numbers entered (not including the -1) are even
  • outputs the count of even numbers once the loop has finished.

(a) Write an algorithm, using OCR Exam Reference Language or a high-level programming language, to carry out this task. [5]

(b) State the output of your program when the user enters 4, 7, 10, 0, -1. [1]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session