AQA GCSE Computer Science June 2024 Paper 1, Question 7: the stock code program
AQA 8525 June 2024 Paper 1, Question 7: write a Python program that builds a stock code such as S1WIM from a sweet's ID, the first two letters of its name and the first letter of its brand. A model answer, the four marks explained, and the program to run.
Question 7 of the AQA GCSE Computer Science Paper 1 sat on 15 May 2024 (8525/1B, the Python paper) is a 4 mark program about string handling: pick characters out of strings and join them together.
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
A sweet shop makes a stock code from three things: the sweetID, the first and second letters of the sweetName, and the first letter of the brand. So S1, WINE GUMS and MAYNARDS make S1WIM.
The program should get the user to enter the three values, create the stock code, and assign it to a variable called code.
A model answer
sweetID = input("Sweet ID: ")
sweetName = input("Sweet name: ")
brand = input("Brand: ")
code = sweetID + sweetName[0] + sweetName[1] + brand[0]
sweetName[0:2] does the job of sweetName[0] + sweetName[1] in one slice.
Notice what is not there: no print. The question says assign it to code. It does not ask for output, and the mark scheme ignores a print if you add one.
Where the four marks are
- the idea of using concatenation (a design mark, given even if the details are wrong);
- inputting the three values into sensibly named variables;
- getting each part of the code right;
- assigning the result to a variable called
code. No other name is accepted.
Any error caps you at 3.
Where the marks are lost
- Counting from 1. The first letter is
[0]and the second is[1].sweetName[1] + sweetName[2]gives IN. - Commas for joining.
code = sweetID, sweetName[0]makes a tuple, not a string. The mark scheme rejects commas. Use+. sweetName[0:1]. A slice stops before its second number, so that is one letter. Two letters is[0:2].- A different variable name.
stockCodeis a better name, and it loses the mark. Use the name you are given.
Run it
Type the three values. The robot's light goes green when the code is made.
The program
from bugbot import *
connect()
sweetID = input("Sweet ID: ")
sweetName = input("Sweet name: ")
brand = input("Brand: ")
code = sweetID + sweetName[0] + sweetName[1] + brand[0]
led("green")
print(code)
Now change it
Type a sweet name with only one letter, such as X. The program crashes with an index error, because there is no second letter. Make it robust: keep asking for the name until it has at least two characters.
Answer
After the input, add a loop: while len(sweetName) < 2, ask for the name again. That is a length check.Questions
What is the answer to AQA GCSE Computer Science 2024 Paper 1 Question 7?
Input sweetID, sweetName and brand, then code = sweetID + sweetName[0] + sweetName[1] + brand[0].
How do I get the first letter of a string in Python?
Use index 0: name[0]. The second letter is name[1]. Indexing starts at 0.
What does a slice such as name[0:2] mean?
The characters from position 0 up to, but not including, position 2. That is the first two characters.
More from this paper
- Question 6: Essay marks with penalties for late essays, never below 0 7 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 14: Local variables, and a subroutine that counts busy days and returns the count 7 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
- F3.1 String handling Strings, lists and records
- F1.7 Input from the user Programming basics
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.