Question 15

AQA Computer Science June 2024 Paper 1B (8525/1B)GCSE8 marks

On the specification

3.2 Programming
Question text

15 A programmer is writing a game. box The game uses a row of cells represented as a list. Figure 20 shows an example. Figure 20 1 2 3 4 5 6 7 X X Figure 21 describes how the game is to be played. Figure 21 • The player starts at position 0 in a row of cells. • The aim of the game is for the player to reach the end of the row. • At each turn the player must enter either 1 or 2 o if the player enters 1, the player’s position increases by 1 o if the player enters 2, the player’s position increases by 2 • If the player’s position goes beyond the end of the row or contains an X: o the message Bad move is displayed o the player goes back to position 0 • These steps are repeated until the player reaches the end of the row. • If the player reaches the end of the row the game is finished. For example, using the list in Figure 20: • the player starts in position 0 1 2 3 4 5 6 7 X X • if the player enters a 1, then they move to position 1 1 2 3 4 5 6 7 X X • if the player then enters a 2, Bad Move is displayed as position 3 contains an X 1 2 3 4 5 6 7 X X Bad move • the player then goes back to position 0 1 2 3 4 5 6 7 X X • if the player then enters a 2, they move to position 2 1 2 3 4 5 6 7 X X • if the player then enters a 2, they move to position 4 1 2 3 4 5 6 7 X X • if the player then enters a 1, they move to position 5 1 2 3 4 5 6 7 X X • if the player then enters a 2, the game finishes. 1 2 3 4 5 6 7 X X Figure 22 shows part of a Python program that will be used for the game. box Figure 22 pos = 0 lastPos = len(row) - 1 while pos < lastPos: pos is a variable that contains the player’s current position. Extend the program from Figure 22 so that the game works as described in Figure 21, on page 37. When writing your program you should assume: • there is a list called row • the number of X characters in row can vary • the position of the X characters in row can vary • the X characters have already been added to the list called row • the row list can be of any length. You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer. The answer grid below contains vertical lines to help you indent your code. [8 marks] pos = 0 lastPos = len(row) - 1 while pos < lastPos: