AQA GCSE Computer Science June 2022 Paper 1, Question 14.2: the checkWinner subroutine

AQA 8525 June 2022 Paper 1, Question 14.2: write a Python subroutine that takes a 2D bingo ticket as a parameter, counts the asterisks and outputs Bingo or the count. A model answer, the eight marks explained, and the subroutine to run.

Past paper questionAQA 8525/1BJune 2022 Paper 18 marksWrite a program

Question 14.2 is the last question of the AQA GCSE Computer Science June 2022 Paper 1 (8525/1B, the Python paper). It is worth 8 marks, and it is the only question on the paper that asks you to write a subroutine and not just a program. Half of the marks are for design, so the shape of your answer matters as much as the detail.

We do not copy the exam paper here. Open it beside this page: AQA June 2022 Paper 1B question paper (PDF). When you have finished, check the mark scheme too.

The question in short

A bingo ticket is a 3 by 3 two-dimensional array of key terms. When the player gets a term, it is replaced with an asterisk, *.

Write a subroutine called checkWinner that:

  • takes the ticket array as a parameter;
  • counts the asterisks in it;
  • outputs Bingo if there are nine;
  • outputs the number of asterisks if there are fewer than nine.

You must write your own counting routine, and not use a built-in count function.

Plan before you write

  1. A heading: def checkWinner(ticket):. That is two marks before you have done anything.
  2. A counter, starting at 0.
  3. A loop inside a loop, to visit all nine squares.
  4. An if that adds 1 when the square is an asterisk.
  5. After the loops, an if and else for the output.

A model answer

def checkWinner(ticket):
    count = 0
    for row in range(3):
        for column in range(3):
            if ticket[row][column] == "*":
                count = count + 1
    if count == 9:
        print("Bingo")
    else:
        print(count)

Where the eight marks are

Four marks are for design:

  • defining a subroutine called checkWinner;
  • passing the whole ticket array in as a parameter;
  • using iteration or selection to try to reach every element;
  • using selection for the output.

Four marks are for a program that works:

  • a counter set to 0 and increased in the right place;
  • index numbers that reach every element of the array;
  • a condition that compares an element with "*";
  • Bingo and the count output in the right places.

Any error in the code caps you at 7.

Nine separate if statements, one for each square, also get full marks. It is a poor way to write it, but it meets the question. Loops are quicker to write and harder to get wrong.

Where the marks are lost

  • No def line. Writing the counting code on its own is a program, not a subroutine. That gives away two design marks.
  • def checkWinner(): with no parameter. The question says the ticket is passed in.
  • ticket.count("*"). The question bans built-in counting. It would not even work: ticket is a list of rows, and no row is equal to "*".
  • Setting count = 0 inside a loop. It wipes the count on every pass.
  • Printing inside the loops. The output happens once, after everything has been counted.
  • return with no output. The question says output. Returning the count does not print anything.

Run it

The subroutine, called on the ticket from the paper's example and on a full ticket. The robot's light goes green for Bingo.

The first ticket has 4 asterisks, so it prints 4. The second has 9, so it prints Bingo.
The program
from bugbot import *
connect()

def checkWinner(ticket):
    count = 0
    for row in range(3):
        for column in range(3):
            if ticket[row][column] == "*":
                count = count + 1
    if count == 9:
        led("green")
        print("Bingo")
    else:
        print(count)

ticket = [["CPU", "ALU", "*"],
          ["*", "*", "LAN"],
          ["Register", "Cache", "*"]]
checkWinner(ticket)

full = [["*", "*", "*"],
        ["*", "*", "*"],
        ["*", "*", "*"]]
checkWinner(full)
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Now change it

Real bingo also pays out for a line. Write a second subroutine, checkLine(ticket), that outputs Line if any row is all asterisks. Then make it check the columns too.

Answer For each row, count the asterisks in that row only, by setting the count to 0 at the start of each row. If the count for a row reaches 3, output Line. For columns, swap the loops so that the outer loop is the column and the element is ticket[row][column] as before.

Questions

What is the answer to AQA GCSE Computer Science 2022 Paper 1 Question 14.2?

Define checkWinner with ticket as a parameter. Set a counter to 0, use two nested for loops over range(3) to visit every element, and add 1 when the element equals "*". After the loops, print Bingo if the counter is 9, and otherwise print the counter.

How do you write a subroutine in Python?

Start with def, the name, and the parameters in brackets, followed by a colon. Indent the body underneath. A subroutine that gives a value back uses return. One that only displays something uses print.

How do you pass an array to a subroutine?

Put a parameter name in the brackets of the def line and use that name inside the subroutine. When you call the subroutine, put the array's name in the brackets of the call.

More from this paper

Every AQA 8525 question we have worked

Learn it step by step

  1. F3.5 Two-dimensional arrays Strings, lists and records
  2. F4.1 Writing functions Functions and structured code
  3. F13.4 Programming questions Exam preparation
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by AQA, and the question paper and mark scheme remain AQA's copyright. Read them on AQA's site with the links on this page.