
Scenario
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:
- The firstname and lastname of the passenger cannot be left blank,
- The airport codes (departure and arrival) have to be exactly 3 characters long,
- The airport codes (departure and arrival) should be automatically converted to UPPERCASE,
- 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,
- The gate number has to be based on the following format: 1 uppercase letter + 2-digit number,
- The flight number has to be based on the following format: 2 uppercase letters + 4-digit number,
- The departure and arrival times must be in the 12:60 AM/PM format,
- The date must be in the DD/MM/YYYY format.
Validation Techniques
e.g. To retrieve a username in lower case:
username = input("Enter your username:").lower()
e.g. To retrieve a last name in title case:
lastname = input("Enter your last name:").title()
e.g. To retrieve a postcode in upper case:
postcode = input("Enter your postcode:").upper()
You can also remove all leading and tailing space from a user input you can use the .strip() method.
name = input("Enter your name:").strip()
Input Validation: Presence Check
name = input("Enter your name:").strip()
if name=="":
print("Empty name!")
else:
print("Thank you!")
Input Validation: Type Check – Integer?
number = input("Type a number:")
if number.isdigit():
print("This is a number")
else:
print("This is not a whole number")
Input Validation: Range Check
number = int(input("Type a number between 1 and 5:"))
if number>=1 and number<=5:
print("Valid number")
else:
print("Invalid number")
Input Validation: Lookup Check
drive = input("Can you drive?").lower()
if drive in ["yes","no"]:
print("Valid answer")
else:
print("Invalid answer")
Input Validation: Character Check
email = input("Type your e-mail address:")
if "@" in email:
print("Valid e-mail address")
else:
print("Invalid e-mail address")
postcode = input("Type your postocode:").upper()
if postcode[0] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and postcode[1] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and postcode[2] in "123456789":
print("Valid postcode")
else:
print("Invalid postcode")
Input Validation: Length Check
password = input("Type a password:")
if len(password)>=8:
print("Valid password")
else:
print("Invalid password")
Try Again! Using a While Loop:
name = input("Enter your name:")
while name=="":
print("You must enter your name! Please try again!")
name = input("Enter your name:")
print("Welcome " + name)
You can investigate more advance approaches to implement validation subroutines on this blog post.
Complete the code

Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area
For this challenge we will create a maths quiz consisting of ten arithmetic questions. Each question will be randomly generated using two random operands between 1 and 12 and one random operator, either + (addition), – (subtraction) or x (multiplication). We will not include the division operator as this could result in a decimal value.
Did you know that every colour on the screen can be represented using an RGB code (Red, Green, Blue) code. This code consists of three numbers between 0 and 255, indicating how much red, green and blue are used to recreate the colour. For instance the RGB code for:
In the Harry Potter series of novels written by British author J. K. Rowling, The Sorting Hat is a magical hat at Hogwarts that determines which of the four school Houses each new student belongs most to. These four Houses are Gryffindor, Hufflepuff, Ravenclaw, and Slytherin.

For this challenge we will write a program where the end-user has to type a password. The program will then return a score to tell the end-user how secure their password is based on the following criteria:
For this challenge we are going to write a Python program which will ask the end-user to enter their date of birth in the following format: dd/mm/yyyy.





