Boarding Pass Validation



You are writing a computer program for an airline company. The program will be used at a check-in desk to generate and print custom boarding passes.

The program captures several user inputs before generating the pass.

In order to make your program more robust, you decide to implement validation routines so that any invalid input is detected and automatically rejected by the program.

Your task is to complete the code below to implement the following validation checks:

  1. The firstname and lastname of the passenger cannot be left blank,
  2. The airport codes (departure and arrival) have to be exactly 3 characters long,
  3. The airport codes (departure and arrival) should be automatically converted to UPPERCASE,
  4. The program should ask whether or not a QR code will be printed on the boarding pass. Only a “Yes” or a “No” answer should be accepted,
  5. The gate number has to be based on the following format: 1 uppercase letter + 2-digit number,
  6. The flight number has to be based on the following format: 2 uppercase letters + 4-digit number,
  7. The departure and arrival times must be in the 12:60 AM/PM format,
  8. The date must be in the DD/MM/YYYY format.

Validation Techniques

String CasePresence CheckInteger OnlyRange CheckLookup CheckCharacter CheckLength CheckTry again!
In Python you can change the case of a sting using .lower(), .upper() and .title() method.

e.g. To retrieve a username in lower case:

e.g. To retrieve a last name in title case:

e.g. To retrieve a postcode in upper case:

You can also remove all leading and tailing space from a user input you can use the .strip() method.

Input Validation: Presence Check

Input Validation: Type Check – Integer?

Input Validation: Range Check

Input Validation: Lookup Check

Input Validation: Character Check

Input Validation: Length Check

Try Again! Using a While Loop:

You can investigate more advance approaches to implement validation subroutines on this blog post.

Complete the code



The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: