AQA GCSE Computer Science June 2024 Paper 1, Question 14: the countDays subroutine

AQA 8525 June 2024 Paper 1, Question 14: state a property of local variables, then write a Python subroutine countDays that takes a number of days, inputs the visitors for each day, counts the days over 200 and returns the count. A model answer and the marks explained.

Past paper questionAQA 8525/1BJune 2024 Paper 17 marksWrite a program

Question 14 of the AQA GCSE Computer Science Paper 1 sat on 15 May 2024 (8525/1B, the Python paper) asks one thing about local variables (1 mark) and then for a whole subroutine (6 marks): a parameter, a loop, a count and a return.

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

Part 1: a property of local variables

One of these:

  • they can only be used inside the subroutine they are made in;
  • they only exist while the subroutine is running.

The question asks for something that is not true of all variables. "They store a value" is true of every variable, so it gets nothing.

Part 2: the question in short

Write a subroutine that:

  • is called countDays;
  • has the number of days a museum was open last month as a parameter;
  • gets the user to enter the number of visitors for each of those days;
  • counts the days that had more than 200 visitors;
  • returns the count.

A model answer

def countDays(days):
    count = 0
    for day in range(days):
        visitors = int(input("Visitors: "))
        if visitors > 200:
            count = count + 1
    return count

Where the six marks are

Two marks are for design: a definite loop (a for), and a selection that checks the visitor numbers.

Four marks are for a program that works:

  • the subroutine and its parameter defined correctly;
  • taking an input once for each day, as many times as the parameter says;
  • a counter that starts at 0 and goes up by one under the right condition;
  • returning the count.

Any error caps you at 5.

Where the marks are lost

  • days = int(input()) inside the subroutine. The number of days is the parameter. Asking for it throws the parameter away.
  • print(count). The question says return.
  • >= 200. "More than 200" does not include 200.
  • count = 0 inside the loop. The count is wiped for every day.
  • return inside the loop. The subroutine would stop after the first day. It lines up with the for, not inside it.
  • No def line. Without it, it is a program and not a subroutine.

Run it

The subroutine, called for a museum that was open for 4 days. The robot drives 10 cm for every busy day.

Enter 150, 201, 200 and 450. Two days were over 200: the day with exactly 200 does not count.
The program
from bugbot import *
connect()

def countDays(days):
    count = 0
    for day in range(days):
        visitors = int(input("Visitors: "))
        if visitors > 200:
            count = count + 1
    return count

busy = countDays(4)
print(busy, "days had more than 200 visitors")
forward(60, distance=busy * 10)
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.

Questions

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

def countDays(days): set count to 0, loop days times, input the visitors as an integer, add 1 to count if visitors is more than 200, and return count after the loop.

What is a local variable?

A variable declared inside a subroutine. It can only be accessed from inside that subroutine, and it exists only while the subroutine is running.

Why use a for loop here and not a while loop?

Because the number of repeats is known before the loop starts: it is the parameter. A for loop is definite iteration, and the mark scheme gives a design mark for choosing it.

More from this paper

Every AQA 8525 question we have worked

Learn it step by step

  1. F4.1 Writing functions Functions and structured code
  2. F4.3 Local and global variables Functions and structured code
  3. F2.7 Loop patterns Decisions and loops
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.