Photo AI

A programmer is writing a game - AQA - GCSE Computer Science - Question 13 - 2023 - Paper 1

Question icon

Question 13

A-programmer-is-writing-a-game-AQA-GCSE Computer Science-Question 13-2023-Paper 1.png

A programmer is writing a game. The game uses a 3 x 3 grid containing nine squares. In the game, a square on the grid is referred to by a letter and a number. For e... show full transcript

Worked Solution & Example Answer:A programmer is writing a game - AQA - GCSE Computer Science - Question 13 - 2023 - Paper 1

Step 1

Extend the program from Figure 15

96%

114 rated

Answer

# Initializing the check variable
check = False
while not check:
    square = ""
    # Loop for obtaining valid reference input
    while len(square) != 2:
        square = input("Enter grid reference (eg C2): ")
        square = square.upper()
    # Extract the characters
    row = square[1]
    col = square[0]
    valid_columns = ['A', 'B', 'C']
    valid_rows = ['1', '2', '3']
    # Check conditions for validity
    if col in valid_columns and row in valid_rows:
        check = True  # Valid grid reference
    else:
        print("Invalid grid reference. Please enter again.")

Step 2

Use the variable check

99%

104 rated

Answer

The variable check is utilized to control the loop, ensuring the program keeps asking for input until a valid reference is provided.

Step 3

Repeat the input until a valid grid reference is entered

96%

101 rated

Answer

The outer while loop continues until check is set to True, indicating that a valid reference has been entered.

Step 4

Get the user to enter a grid reference

98%

120 rated

Answer

Within the loop, the program prompts the user for input using the input function.

Step 5

Ensure that the appropriate message is displayed if the grid reference entered is not valid

97%

117 rated

Answer

An error message is printed in the else clause if the entered reference doesn't match the valid options.

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

;