Question 3
AQA Computer Science June 2024 Paper 1B (8525/1B)GCSE6 marks
On the specification
- 3.1
- 3.2 Programming
- 3.2
- 3.2 Programming
- 3.3
- 3.2 Programming
Question text
3 Figure 3 shows an incomplete Python program for a number guessing game. box • Line numbers are included but are not part of the program. Figure 3 1 import random 2 3 print("Enter a number") 4 userNumber = int(input()) 5 while userNumber < 1 or userNumber > 100: 6 print("Invalid number") 7 userNumber = int(input()) 8 print("Valid number entered") 9 if randomNumber == userNumber: 10 print("Number guessed correctly") 3.1 The program should generate a random number between 1 and 100 (including 1 and 100). This will be the number the user has to guess. Write the Python code that should be used on line 2 in Figure 3 to: • generate a random number between 1 and 100 inclusive • assign this number to the appropriate variable from the program. You must use random.randrange(a, b) in your Python code. random.randrange(a, b) generates a random integer in the range a to b starting at a but finishing one before b [2 marks] 3.2 Complete the test plan in Table 1 to test the validation of userNumber in the box program in Figure 3. [2 marks] Table 1 Test number Test type Test data Expected result 1 Erroneous 150 2 Boundary 3 Normal Valid number entered 3.3 In an earlier version of the program in Figure 3, line 5 contained one syntax error and one logic error: whil userNumber < 1 or userNumber >= 100: Complete the table to describe the errors in the program on line 5. [2 marks] Error type Description Syntax error Logic error