Answer to Question #333167 in Python for maitha

Question #333167

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


1
Expert's answer
2022-04-25T04:43:05-0400


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
)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS