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.
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 = 0inside the loop. The count is wiped for every day.returninside the loop. The subroutine would stop after the first day. It lines up with thefor, not inside it.- No
defline. 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.
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)
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
- Question 6: Essay marks with penalties for late essays, never below 0 7 marks
- Question 7: Build a stock code with string indexing and concatenation 4 marks
- Question 11: Authenticate against two username and password pairs until valid 7 marks
- Question 12.6, 12.7: Use given subroutines to check a row and to play until solved 10 marks
- Question 15: Move 1 or 2 along a row of cells, back to 0 on an X or past the end 8 marks
Every AQA 8525 question we have worked
Learn it step by step
- F4.1 Writing functions Functions and structured code
- F4.3 Local and global variables Functions and structured code
- F2.7 Loop patterns Decisions and loops
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.