2.2.1 Programming fundamentals Practice Questions
GCSE · Paper 2 · Computational thinking, algorithms and programming · 12 practice questions · 42 marks
Exam questions for 2.2.1 Programming fundamentals
12 practice questions (42 marks) with mark schemes
Answer each question, reveal the mark scheme, then award yourself marks. Scores and answers are saved in this browser so you can see which topics need more work.
Practice questions
- Question 1Practice question · J277/02 style4 marks
State the value of each expression. (a) 23 MOD 4 [1] (b) 23 DIV 4 [1] (c) 23 / 4 [1] (d) 3 ^ 3 [1]
Show mark scheme
(a) 3 (1) (b) 5 (1) (c) 5.75 (1) (d) 27 (1) Method: 23 divided by 4 is 5 remainder 3, so DIV gives 5 and MOD gives 3. 23 / 4 = 5.75. 3 ^ 3 = 3 * 3 * 3 = 27.
Mark yourself: how many marks did you get?/ 4 - Question 2Practice question · J277/02 style2 marks
A shop program uses the line const vat = 0.2 (a) Give one difference between a variable and a constant. [1] (b) Give one benefit of using a constant for the VAT rate instead of typing 0.2 each time it is needed. [1]
Show mark scheme
(a) The value of a variable can change while the program runs, but the value of a constant cannot / a constant is set once (1) (b) If the rate changes, it only needs to be changed in one place / the code is easier to read because the name shows what the number means / fewer typing mistakes (1)
Mark yourself: how many marks did you get?/ 2 - Question 3Practice question · J277/02 style3 marks
Each program fragment below uses one of the three programming constructs: sequence, selection or iteration. State the construct used in each fragment. Fragment A
01 x = 4 02 y = x * 2 03 print(y)Fragment B
01 while x < 10 02 x = x + 3 03 endwhileFragment C
01 if x > 3 then 02 print("Big") 03 endifShow mark scheme
Fragment A: sequence (1) Fragment B: iteration (1) Fragment C: selection (1)
Mark yourself: how many marks did you get?/ 3 - Question 4Practice question · J277/02 style4 marks
A program contains this code.
01 total = 0 02 count = 0 03 for i = 1 to 6 04 if i MOD 2 == 0 then 05 total = total + i 06 count = count + 1 07 endif 08 next i 09 print(total) 10 print(count)(a) State the two values printed, in order. [2] (b) State how many times line 04 is run. [1] (c) State how many times line 05 is run. [1]
Show mark scheme
(a) 12 (1) then 3 (1) (b) 6 (1) (c) 3 (1) Method: i takes the values 1 to 6. The even values are 2, 4 and 6, because only these give a remainder of 0 when divided by 2. total = 2 + 4 + 6 = 12 and count = 3. Line 04 runs once for each value of i, which is 6 times.
Mark yourself: how many marks did you get?/ 4 - Question 5Practice question · J277/02 style3 marks
A program contains this code.
01 n = 100 02 steps = 0 03 while n > 10 04 n = n DIV 2 05 steps = steps + 1 06 endwhile 07 print(n) 08 print(steps)(a) State the value of n that is printed. [1] (b) State the value of steps that is printed. [1] (c) State the type of iteration used in this program. [1]
Show mark scheme
(a) 6 (1) (b) 4 (1) (c) Condition-controlled (iteration / loop) (1) Method: n goes 100, 50, 25, 12, 6. After each change steps goes 1, 2, 3, 4. When n is 6 the condition n > 10 is False, so the loop stops.
Mark yourself: how many marks did you get?/ 3 - Question 6Practice question · J277/02 style3 marks
A program contains this code.
01 do 02 num = int(input("Enter a positive number")) 03 until num > 0The user types -4, then 0, then 7. (a) State how many times line 02 is run. [1] (b) State the value of num when the loop ends. [1] (c) Give one way in which a do-until loop differs from a while loop. [1]
Show mark scheme
(a) 3 (1) (b) 7 (1) (c) A do-until loop always runs at least once because the condition is checked at the end / a while loop checks the condition at the start so it may not run at all (1)
Mark yourself: how many marks did you get?/ 3 - Question 7Practice question · J277/02 style3 marks
Complete the program so that it prints Distinction for a mark of 70 or more, Merit for a mark of 50 to 69 and Pass for any other mark. Write the missing keyword for each gap.
01 mark = int(input("Enter mark")) 02 if mark >= 70 then 03 print("Distinction") 04 ________ mark >= 50 then 05 print("Merit") 06 ________ 07 print("Pass") 08 ________Show mark scheme
Line 04: elseif (1) Line 06: else (1) Line 08: endif (1)
Mark yourself: how many marks did you get?/ 3 - Question 8Practice question · J277/02 style2 marks
A program contains this code.
01 switch day : 02 case "Sat": 03 print("Weekend") 04 case "Sun": 05 print("Day off") 06 default: 07 print("Work") 08 endswitchState what is printed when day holds: (a) "Sun" [1] (b) "Tue" [1]
Show mark scheme
(a) Day off (1) (b) Work (1). No case matches "Tue", so the default part runs.
Mark yourself: how many marks did you get?/ 2 - Question 9Practice question · J277/02 style3 marks
This program should ask for 10 numbers, print their total, and print Large if the total is more than 100. It contains three errors.
01 total = 0 02 for i = 1 to 9 03 num = int(input("Enter a number")) 04 total + num 05 next i 06 print(total) 07 if total > 100 then 08 print("Large")Identify each error and say how to correct it.
Show mark scheme
Error 1: line 02. The loop only runs 9 times / it should run 10 times. Change to for i = 1 to 10 (or for i = 0 to 9) (1) Error 2: line 04. The total is not stored / it is not an assignment. Change to total = total + num (1) Error 3: after line 08. The if has no endif. Add endif on a new line 09 (1) Award marks for each error found and corrected. Do not award a mark for a change to a line that was already correct.
Mark yourself: how many marks did you get?/ 3 - Question 10Practice question · J277/02 style5 marks
A cinema charges by age group. A child is under 13, a teen is 13 to 17 and an adult is 18 or over. Write a program, in the OCR Exam Reference Language or a high-level programming language, that asks the user to enter their age and then prints Child, Teen or Adult. [5]
Show mark scheme
Example answer:
age = int(input("Enter your age")) if age < 13 then print("Child") elseif age <= 17 then print("Teen") else print("Adult") endif(1) Age is input and stored in a variable, cast to an integer (1) First condition is correct (age < 13, or age <= 12) and prints Child (1) Second condition is correct and prints Teen. Accept elseif age >= 13 AND age <= 17 (1) Third case is handled with else / a correct condition (age >= 18) and prints Adult (1) Structure is correct: the selection is closed with endif and the three messages are printed in the right branches (no mark if the ranges overlap or leave gaps) Accept the same logic in a high-level language. Do not accept English sentences or flow charts.
Mark yourself: how many marks did you get?/ 5 - Question 11Practice question · J277/02 style6 marks
A program adds up numbers entered by the user. The user enters numbers one at a time and types 0 when they have finished. Write a program, in the OCR Exam Reference Language or a high-level programming language, that does this and then prints the total. [6]
Show mark scheme
Example answer using do-until:
total = 0 do num = int(input("Enter a number")) total = total + num until num == 0 print(total)Example answer using while:
total = 0 num = int(input("Enter a number")) while num != 0 total = total + num num = int(input("Enter a number")) endwhile print(total)(1) total set to 0 before the loop (1) A loop that repeats (condition-controlled) (1) A number is input inside the loop and stored (1) The input is cast to a number (int or float) (1) total is increased by the input number (total = total + num) (1) The loop stops when 0 is entered (correct condition), and total is printed after the loop Adding the final 0 to the total does not change it, so either method is correct.
Mark yourself: how many marks did you get?/ 6 - Question 12Practice question · J277/02 style4 marks
The variables are set as follows.
01 a = 8 02 b = 3 03 colour = "red"State whether each condition is True or False. (a) a > 5 AND b > 5 [1] (b) a > 5 OR b > 5 [1] (c) NOT (a == 8) [1] (d) colour == "red" AND NOT (b < 2) [1]
Show mark scheme
(a) False (1). a > 5 is True but b > 5 is False, and AND needs both to be True. (b) True (1). a > 5 is True, and OR needs only one. (c) False (1). a == 8 is True and NOT reverses it. (d) True (1). colour == "red" is True. b < 2 is False, so NOT (b < 2) is True. True AND True is True.
Mark yourself: how many marks did you get?/ 4
- •Practice answering questions under timed conditions
- •Check your answers against the mark scheme carefully
- •Focus on understanding the marking points, not just memorising answers
- •Come back to the questions you dropped marks on a few days later