AQA GCSE Computer Science June 2024 Paper 1, Question 10: subroutines that call subroutines
AQA 8525 June 2024 Paper 1, Question 10: work out what is printed when First calls Second and Second calls Third, for the values 3, 4, 4 and then 3, 4, 8. The parameter order trap, both answers worked through, and the program to run.
Question 10 of the AQA GCSE Computer Science Paper 1 sat on 15 May 2024 (8525/1B, the Python paper) is only 2 marks, and it is easy to get wrong. Three subroutines call each other, and every one of them uses the names p1 and v1 for something different.
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.
The question in short
First(p1, p2, p3)addsp2andp3to makev1, then printsSecond(v1, p1).Second(p1, p2)adds its two parameters to makev1. Ifv1is greater than 12, it addsThird(p1)tov1. It returnsv1.Third(p1)returns 2 ifp1is greater than 3, and 0 otherwise.
The thing to get straight
Parameters are matched by position, not by name. First calls Second(v1, p1). So inside Second, the name p1 holds what First called v1, and p2 holds what First called p1. Each subroutine has its own private set of names.
Write the values down afresh each time you enter a subroutine.
Part 1: First(3, 4, 4)
In First: p1 = 3, p2 = 4, p3 = 4. v1 = 4 + 4 = 8. It calls Second(8, 3).
In Second: p1 = 8, p2 = 3. v1 = 8 + 3 = 11. Is 11 greater than 12? No. It returns 11.
The output is 11.
Part 2: First(3, 4, 8)
In First: v1 = 4 + 8 = 12. It calls Second(12, 3).
In Second: p1 = 12, p2 = 3. v1 = 15. Is 15 greater than 12? Yes, so it calls Third(12).
In Third: p1 = 12. Is 12 greater than 3? Yes. It returns 2.
Back in Second: v1 = 15 + 2 = 17. It returns 17.
The output is 17.
Where the marks are lost
- Passing the wrong value to
Third.SecondcallsThird(p1)with its ownp1, which is 12, not the 3 thatFirstcalledp1. With 3,Thirdwould return 0 and the answer would be 15. - Adding all three numbers. 3 + 4 + 4 = 11 happens to give the first answer, and 3 + 4 + 8 = 15 does not give the second.
- Forgetting that
Secondreturns andFirstprints. Only one thing is printed, once.
Run it
The program with a print at the start of every subroutine, so that you can see which values arrive where. Change the call at the bottom.
The program
from bugbot import *
connect()
def First(p1, p2, p3):
print("First has", p1, p2, p3)
v1 = p2 + p3
print(Second(v1, p1))
def Second(p1, p2):
print(" Second has", p1, p2)
v1 = p1 + p2
if v1 > 12:
v1 = v1 + Third(p1)
return v1
def Third(p1):
print(" Third has", p1)
if p1 > 3:
return 2
else:
return 0
First(3, 4, 4)
First(3, 4, 8)
Questions
What are the answers to AQA GCSE Computer Science 2024 Paper 1 Question 10?
11 for the values 3, 4 and 4. 17 for the values 3, 4 and 8.
How are arguments matched to parameters?
By position. The first argument in the call goes to the first parameter in the definition, the second to the second, and so on. The names used in the calling code do not matter.
Can two subroutines use the same variable name?
Yes. Parameters and variables made inside a subroutine are local to it, so p1 in one subroutine is a different variable from p1 in another.
More from this paper
- Question 1: LEN, POSITION, a data type, assignment, and a two line program 6 marks
- Question 2: Follow an IF, ELSEIF chain with NOT, OR, AND and MOD 5 marks
- Question 5: The output of a nested IF for three pairs of inputs 3 marks
- Question 12.1 to 12.5: A sliding puzzle: move tiles, and read nested loops that find the blank 7 marks
Every AQA 8525 question we have worked
Learn it step by step
- F4.2 Parameters and return values Functions and structured code
- F4.3 Local and global variables Functions and structured code
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.