AQA GCSE Computer Science June 2022 Paper 1, Question 9: SUBSTRING and string handling
AQA 8525 June 2022 Paper 1, Question 9: string handling in pseudo-code. Indexing a string, the length of an array, SUBSTRING with both ends included, and building Thomasrah. Worked through, with the Python to run.
Question 9 of the AQA GCSE Computer Science June 2022 Paper 1 (8525/1B, the Python paper) is four parts on string handling in AQA pseudo-code, worth 5 marks. One fact decides most of them: AQA's SUBSTRING includes both the start and the end position. Python's slicing does not.
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
The algorithm makes an array called names holding Lily and Thomas, a string name1 holding Sarah, and a string name2 holding Freddie. Then it outputs three things:
name1[0];LEN(names);SUBSTRING(0, 3, name1).
The paper gives an example: SUBSTRING(3, 5, 'programming') returns 'gra'. Count it: p is 0, r is 1, o is 2, g is 3, r is 4, a is 5. Three characters, so position 5 is included.
Work it through
Write the index numbers over Sarah before you do anything else.
| 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| S | a | r | a | h |
9.1: name1[0]. Position 0 of Sarah is S. Not F: that would be name2.
9.2: LEN(names). names is the array, and it has 2 items. Not 5 (the length of Sarah) and not 10 (the letters in Lily and Thomas).
9.3: SUBSTRING(0, 3, name1). Positions 0, 1, 2 and 3: Sara. Four characters, because both ends are included.
9.4: make Thomasrah. That is Thomas with rah on the end. Thomas is names[1]. In Sarah, rah is positions 2, 3 and 4. So the two lines are:
var ← SUBSTRING(2, 4, name1) and OUTPUT names[1] + var
One mark for 2 and 4, one mark for 1.
Where the marks are lost
Sarfor 9.3. That is what Python'sname1[0:3]gives. AQA'sSUBSTRINGis inclusive at both ends. Use the example the paper gives you to check which rule is in play.SUBSTRING(2, 5, name1)for 9.4. Sarah has no position 5.names[2]for Thomas. Counting starts at 0, so Thomas is at 1.- The length of the wrong thing in 9.2.
nameswith an s is the array.
Run it
Python has no SUBSTRING, so this program defines one that behaves the way AQA's does. Compare it with Python's own slicing in the last line.
The program
from bugbot import *
connect()
def SUBSTRING(start, end, text):
# AQA's version: the end position is included
return text[start:end + 1]
names = ["Lily", "Thomas"]
name1 = "Sarah"
name2 = "Freddie"
print(name1[0])
print(len(names))
var = SUBSTRING(0, 3, name1)
print(var)
var = SUBSTRING(2, 4, name1)
print(names[1] + var)
print("Python's name1[0:3] is", name1[0:3])
Now change it
Using only names, name1, name2 and SUBSTRING, output Fredly. Work out the positions on paper first.
Answer
SUBSTRING(0, 3, name2) is Fred. SUBSTRING(2, 3, names[0]) is ly. Join them with +.Questions
What are the answers to AQA GCSE Computer Science 2022 Paper 1 Question 9?
9.1 is D, the letter S. 9.2 is B, 2. 9.3 is Sara. 9.4 is SUBSTRING(2, 4, name1) and names[1].
Does SUBSTRING in AQA pseudo-code include the end position?
Yes. SUBSTRING(start, end, string) returns the characters from start to end with both included, counting from 0. SUBSTRING(0, 3, 'Sarah') is 'Sara'.
How is Python slicing different from AQA SUBSTRING?
A Python slice text[0:3] stops before position 3, so it gives three characters. AQA's SUBSTRING(0, 3, text) includes position 3, so it gives four. In Python the same result is text[0:4].
More from this paper
- Question 1: MOD, selection, assignment, relational operators and a definite loop 6 marks
- Question 2: Follow a nested IF with AND, then name the data types 6 marks
Every AQA 8525 question we have worked
Learn it step by step
- F3.1 String handling Strings, lists and records
- F3.3 Lists: one-dimensional arrays Strings, lists and records
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.