Skip to content
MathsGenie logo
Open app

Course home

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

Programming concepts

EasyMediumHard
1234567891011121314151617181920212223
Question 11

Library Inventory System

Figure 1 shows a grid representing a 3x3 shelf indexing system in a library archives section.

Figure 1

XYZ
4
5
6Book

Figure 2 shows an incomplete Python program designed to validate the user's shelf code input.

Figure 2

isValid = False
while isValid == False:
    code = ""
    while len(code) != 2:
        code = input("Enter shelf code (e.g. Y5): ")
        code = code.upper()

Extend the program from Figure 2 so it completes the other checks needed to make sure a valid shelf code is entered.

The shelf code is valid if:

  • there are exactly two characters
  • the first character entered is X, Y, or Z
  • the second character entered is 4, 5, or 6

Your extended program must:

  • use the variable isValid
  • repeat the steps until a valid shelf sequence is entered
  • output an appropriate error message if the shelf code entered is not valid

You should use indentation as appropriate, meaningful variable names, and correct Python syntax in your answer.

[6]

Programming concepts Questions

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