Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
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]
Markscheme

Programming concepts Questions

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

298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank