Store the details of the following 3 flights in a 2-dimensional tuple:
Flight number Destination Departure time
EK004 London 12:30
EK012 Paris 14:00
EK052 Male 16:15
Create a function called checkFlightNumber which accepts a flight number as an input parameter. This function will check if the flight number is found in the tuple which contains the flight details and return TRUE of found or FALSE if it is not.
Your program should keep asking for passengers’ (loop)details until the user enters n to stop. The program should first ask for the passengers’ flight number and use the checkFlightNumber function to check if it is valid or not. If checkFlightNumber returns FALSE, your program will print an appropriate error message and ask the user to try again. However, if checkFlightNumber returns TRUE, your program should ask
the user to enter the following passenger details:
1.Name
2.Date of birth
3. Passport number
def check_code(s:str)->bool:
for ch in s:
if(not ch.isalnum()):
return False;
return True;
def check_time(s:str)->bool:
ls=s.split(':')
if(len(ls)<2) or (len(ls)>3):
return False;
return ls[0].isdigit() and ls[1].isdigit();
def checkFlightNumber(s:str)->bool:
ls=s.split()
#first part check code
if len(ls)!=3:
return False
bcode=check_code(ls[0])
btime=check_time(ls[2])
return bcode and btime
ls=list()
n=int(input("Number of passengers: "))
for i in range(n):
fl=input("Please flight number: ")
if(not checkFlightNumber(fl)):
print("Error")
break
nam=input("name:")
passport=input("Input passport data: ")
sd=input("Input BithDate: ")
ln=list()
ln.append(fl)
ln.append(nam)
ln.append(passport)
ls.append(sd)
ls.append(ln)
tp=tuple(ls)
print(tp
)
Comments
Leave a comment