Skip to content
MathsGenie logo
Open app

Course home

  1. GCSE
  2. Computer Science AQA
  3. Question bank

Programming concepts

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637
Question 18

An oceanic research vessel uses a coordinate grid system to map marine wildlife sightings. The grid layout is divided into 3 columns (X, Y, and Z) and 5 rows (1, 2, 3, 4, and 5) as shown in Figure 1.

Figure 1

XYZ
1
2[Sighting]
3
4
5

Figure 2

valid = False
while valid == False:
    sector = ""
    while len(sector) != 2:
        sector = input("Enter research sector ID (e.g. Y3): ")
        sector = sector.upper()

Extend the Python program in Figure 2 so that it completes the validation checks to match the coordinate layout in Figure 1.

Your extended program must:

  • use the variable valid
  • check that the first character of the string sector is a valid column letter (X, Y, or Z)
  • check that the second character of the string sector is a valid row number (1, 2, 3, 4, or 5)
  • change the value of valid to True if both checks are met
  • output an appropriate error message if any part of the sector identifier is invalid.

You should write Python code or precise pseudocode in your answer.

[6]

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts