AQA GCSE Computer Science June 2024 Paper 1, Question 3: the number guessing game
AQA 8525 June 2024 Paper 1, Question 3: write the line that generates a random number from 1 to 100, complete a test plan with erroneous, boundary and normal data, and describe a syntax error and a logic error. Worked through, with the game to run.
Question 3 of the AQA GCSE Computer Science Paper 1 sat on 15 May 2024 (8525/1B, the Python paper) is three 2 mark parts about one short Python program: write a missing line, plan its tests, and describe two errors.
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
The program imports random, reads userNumber, and keeps asking while it is less than 1 or greater than 100. Then it compares userNumber with randomNumber. Line 2 is blank.
Part 1: the missing line
randomNumber = random.randrange(1, 101)
One mark for storing a number in the right variable. Line 9 uses randomNumber, so that is its name. One mark for the random number itself. The paper reminds you that randrange(a, b) stops one before b, so 1 to 100 needs (1, 101).
Part 2: the test plan
| Test | Type | Test data | Expected result |
|---|---|---|---|
| 1 | Erroneous | 150 | Invalid number |
| 2 | Boundary | 100 | Valid number entered |
| 3 | Normal | 50 | Valid number entered |
One mark for test 1's result and test 3's data together. One mark for test 2's data and result, which must agree with each other. AQA accepts 1 or 100 (valid), and also 0 or 101 (invalid), as boundary data. What it will not accept is 101 with "Valid number entered".
The expected results are the program's own messages. Copy them from the code.
Part 3: the two errors
The earlier version of line 5 read whil userNumber < 1 or userNumber >= 100:
- Syntax error:
whilis misspelt. It should bewhile. - Logic error:
>= 100should be> 100. As written, 100 is rejected, and 100 is a valid number.
The same answer in both boxes gets nothing.
Where the marks are lost
random.randrange(1, 100). That can never produce 100.- A new variable name, such as
numberorrandom. It has to match line 9. - A boundary value with the wrong result. Decide which side of the boundary your value is on.
- "It won't work" for the syntax error. Say what is wrong: the keyword is misspelt.
Run it
The finished game. The number is printed at the start so that you can test a correct guess. Try 150, then 100.
The program
from bugbot import *
import random
connect()
randomNumber = random.randrange(1, 101)
print("(the number is", randomNumber, "so you can test a correct guess)")
print("Enter a number")
userNumber = int(input())
while userNumber < 1 or userNumber > 100:
led("red")
print("Invalid number")
userNumber = int(input())
print("Valid number entered")
if randomNumber == userNumber:
led("green")
print("Number guessed correctly")
Questions
What is the answer to AQA GCSE Computer Science 2024 Paper 1 Question 3.1?
randomNumber = random.randrange(1, 101).
What does random.randrange(1, 101) do?
It returns a random whole number from 1 to 100. The first number is included and the second is not.
What is boundary test data?
Data at the edge of the valid range. For a range of 1 to 100, the boundary values are 1 and 100, which should be accepted, and 0 and 101, which should be rejected.
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 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
Every AQA 8525 question we have worked
Learn it step by step
- F3.7 Random numbers Strings, lists and records
- F6.3 Testing and test data Robust programs
- F1.4 Errors: syntax, runtime and logic 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.