Skip to content

2.1.2 Designing, creating and refining algorithms Practice Questions

GCSE · Paper 2 · Computational thinking, algorithms and programming · 12 practice questions · 48 marks

Exam questions for 2.1.2 Designing, creating and refining algorithms

12 practice questions (48 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

  1. Question 1Practice question · J277/02 style4 marks

    A shop program asks the user to enter the length and the width of a room, in metres, and the price of carpet for each square metre. It then works out the cost of carpet for the whole floor and displays it. (a) State two inputs of the program. [2] (b) State the process. [1] (c) State the output. [1]

    Show mark scheme

    (a) Any two from: length of the room / width of the room / price per square metre (1 each, max 2) (b) Multiply the length by the width, then multiply by the price (1) (c) The total cost of the carpet (1)

    Mark yourself: how many marks did you get?
    / 4
  2. Question 2Practice question · J277/02 style3 marks

    A structure diagram for a quiz program is shown as an indented list. Quiz game

        Set up
            Load the questions
            Enter the player name
        Play a round
            Ask a question
            Check the answer
            Update the score
        Finish
            Show the score
            Save the high score

    (a) State what a structure diagram shows. [1] (b) State how many boxes are at the lowest level of this diagram. [1] (c) Give one reason why a programmer draws a structure diagram before writing the code. [1]

    Show mark scheme

    (a) How a problem is broken down into smaller sub-problems / the parts of a program and how they fit together (1) (b) 7 (1). Method: 2 under Set up, 3 under Play a round and 2 under Finish, which is 2 + 3 + 2 = 7. (c) Each part is small and easier to write / each part can be tested on its own / different people can write different parts / it helps the programmer plan (1)

    Mark yourself: how many marks did you get?
    / 3
  3. Question 3Practice question · J277/02 style4 marks

    A programmer is drawing a flowchart. Give the name of the flowchart symbol that is used for each of these. (a) A rounded oval that marks the start of the algorithm. [1] (b) A diamond with a Yes arrow and a No arrow leaving it. [1] (c) A slanted rectangle (a parallelogram) used to show data being entered. [1] (d) A rectangle with an extra vertical line inside each of its two sides. [1]

    Show mark scheme

    (a) Terminal (1) (b) Decision (1) (c) Input/output (1) (d) Sub program (1)

    Mark yourself: how many marks did you get?
    / 4
  4. Question 4Practice question · J277/02 style4 marks

    This program should ask for five numbers, add them up and print the average. It contains two errors.

    01 total = 0
    02 for i = 1 to 5
    03     num = int(input("Enter a number"))
    04     total = total + num
    05 next i
    06 average = total / 4
    07 print(average)
    08 if average >= 10
    09     print("High")
    10 endif

    (a) Identify the line that has a syntax error and write the corrected line. [2] (b) Identify the line that has a logic error and write the corrected line. [2]

    Show mark scheme

    (a) Line 08 (1). if average >= 10 then (1) - the word then is missing. (b) Line 06 (1). average = total / 5 (1) - the loop adds five numbers, so the total must be divided by 5, not 4.

    Mark yourself: how many marks did you get?
    / 4
  5. Question 5Practice question · J277/02 style4 marks
    01 a = 3
    02 b = 1
    03 while a < 40
    04     a = a * 2
    05     b = b + a
    06 endwhile
    07 print(b)

    Complete a trace table for this program. Use a new row each time a value changes. The first row is done for you. [4]

    abOutput
    31
    Show mark scheme
    abOutput
    31
    67
    1219
    2443
    4891
    91

    Marks: the a column 6, 12, 24, 48 (1); the b column 7, 19, 43, 91 (2, award 1 if the first two values are right); output 91 in the output column (1). Method: 3 < 40 so a = 6 and b = 1 + 6 = 7. 6 < 40 so a = 12 and b = 19. 12 < 40 so a = 24 and b = 43. 24 < 40 so a = 48 and b = 91. 48 < 40 is false, so the loop stops.

    Mark yourself: how many marks did you get?
    / 4
  6. Question 6Practice question · J277/02 style4 marks
    01 count = 0
    02 for x = 1 to 3
    03     for y = 1 to 3
    04         if x < y then
    05             count = count + 1
    06         endif
    07     next y
    08 next x
    09 print(count)

    Complete a trace table for this program. Use a column for x, y, count and the output. [4]

    Show mark scheme
    xycountOutput
    0
    110
    121
    132
    212
    222
    233
    313
    323
    333
    3

    Marks: x and y take every pair, with y going 1 to 3 for each x (1); count rises only when x < y, so for (1,2), (1,3) and (2,3) (2, award 1 if one change is wrong); output 3 (1).

    Mark yourself: how many marks did you get?
    / 4
  7. Question 7Practice question · J277/02 style5 marks

    A teacher wants a program that asks for ten test marks, each between 0 and 100, and then prints how many of the marks were 50 or more. Write the program. Write your answer in the OCR Exam Reference Language or a high-level programming language. [5]

    Show mark scheme
    count = 0  // (1 for a variable that starts at 0)
    for i = 0 to 9  // (1 for a loop that runs 10 times)
        mark = int(input("Enter a mark"))  // (1 for an input inside the loop)
        if mark >= 50 then  // (1 for the correct test)
            count = count + 1
        endif
    next i
    print(count)  // (1 for adding one to the count and printing it after the loop)

    Accept for i = 1 to 10 and a while loop with a counter. Do not award the final mark if the print is inside the loop. Check: marks 40, 50, 72 give a count of 2.

    Mark yourself: how many marks did you get?
    / 5
  8. Question 8Practice question · J277/02 style4 marks

    A program asks the user to enter a password. The user has up to three more attempts to correct it.

    01 password = "blue42"
    02 attempts = 0
    03 guess = input("Enter password")
    04 while guess ____ password AND attempts < 3
    05     attempts = attempts + 1
    06     guess = input("Try again")
    07 endwhile
    08 if guess == password then
    09     print("Welcome")
    10 else
    11     print("Locked")
    12 endif

    (a) State the symbol that should replace the gap on line 04. [1] (b) The user enters red and then blue42. State what is printed and the final value of attempts. [2] (c) The user enters a, b, c and d in that order. State what is printed. [1]

    Show mark scheme

    (a) != (1) (b) Welcome (1) and 1 (1). Method: red is not blue42 and attempts is 0, so attempts becomes 1 and the user enters blue42. The condition is now false. (c) Locked (1). Method: the first guess is a, so attempts becomes 1 and the guess is b. Then attempts becomes 2 and the guess is c. Then attempts becomes 3 and the guess is d. The loop stops because attempts is 3, and d does not match the password.

    Mark yourself: how many marks did you get?
    / 4
  9. Question 9Practice question · J277/02 style4 marks

    The code below prints a grade for a mark.

    01 if mark >= 70 then
    02     print("Distinction")
    03 endif
    04 if mark >= 50 AND mark < 70 then
    05     print("Merit")
    06 endif
    07 if mark < 50 then
    08     print("Pass")
    09 endif

    (a) Rewrite the code using if, elseif and else so that it prints the same grades. Write your answer in the OCR Exam Reference Language or a high-level programming language. [3] (b) Give one reason why the new version is better. [1]

    Show mark scheme

    (a)

    if mark >= 70 then  // (1)
        print("Distinction")
    elseif mark >= 50 then  // (1 for elseif with a correct test, no need for the second part of the condition)
        print("Merit")
    else  // (1 for else with the Pass output, and endif at the end)
        print("Pass")
    endif

    (b) It is shorter / easier to read / fewer tests are made / the conditions are not repeated (1)

    Mark yourself: how many marks did you get?
    / 4
  10. Question 10Practice question · J277/02 style6 marks

    A program asks the user for a whole number n between 1 and 12. It then prints the first twelve multiples of n (n times 1, n times 2, up to n times 12), one on each line. If a multiple is greater than 50, it prints "Big" instead of the multiple. Write the program. Write your answer in the OCR Exam Reference Language or a high-level programming language. [6]

    Show mark scheme
    n = int(input("Enter a number"))  // (1 for input stored as an integer)
    for i = 1 to 12  // (1 for a loop that runs 12 times with a correct start and end)
        multiple = n * i  // (1 for working out the multiple)
        if multiple > 50 then  // (1 for a correct test)
            print("Big")  // (1 for printing Big)
        else
            print(multiple)  // (1 for printing the multiple in the else branch)
        endif
    next i

    Accept the multiple worked out inside the print or the if. Accept a while loop with a counter. Check: n = 5 prints 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, Big, Big.

    Mark yourself: how many marks did you get?
    / 6
  11. Question 11Practice question · J277/02 style4 marks
    01 function mystery(n)
    02     result = 0
    03     while n > 0
    04         result = result + n MOD 10
    05         n = n DIV 10
    06     endwhile
    07     return result
    08 endfunction
    09 print(mystery(4721))

    (a) Complete a trace table for the call mystery(4721). Use columns for n and result. [3] (b) State what the function does. [1]

    Show mark scheme

    (a)

    nresult
    47210
    4721
    473
    410
    014

    Output: 14 Marks: n goes 4721, 472, 47, 4, 0 (1); result goes 0, 1, 3, 10, 14 (1); the output 14 (1). (b) It adds up the digits of the number (1)

    Mark yourself: how many marks did you get?
    / 4
  12. Question 12Practice question · J277/02 style2 marks

    (a) State what a trace table is used for. [1] (b) Explain why a trace table can find a logic error but cannot find a syntax error. [1]

    Show mark scheme

    (a) To follow an algorithm by hand and record the values of its variables and outputs / to check what an algorithm does (1) (b) A logic error gives wrong values that show up in the table when the program is followed, but a syntax error is a spelling or rule mistake that stops the program running at all, so there are no values to trace (1)

    Mark yourself: how many marks did you get?
    / 2
General Exam Advice
  • •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