Write a python program to generate the ticket numbers for specified number of passengers traveling in a flight as per the details mentioned below: The ticket number should be generated as airline:src:dest:number where Consider AI as the value for airline src and dest should be the first three characters of the source and destination cities. number should be auto-generated starting from 101 The program should return the list of ticket numbers of last five passengers. Note: If passenger count is less than 5, return the list of all generated ticket numbers.
Answers
Answer:
Explanation:
"The code is following –
tickets = []
airline, source, destination, no_of_passengers = input('Enter the airline:'), input ('Enter the source:')[:3], input('Enter the destination') [:3], int(input('Enter the total number of passengers:'))
for ticket_number in range(101,101+no_of_passengers):
tickets.append ('%s:%s:%s:%d'%(airline,source,destination,ticket_number))
if no_of_passengers > 5:
print(tickets[-5:])
else:
print(tickets)
It would show the output given in the question."
def generate_ticket(airline,source,destination,no_of_passengers):
ticket_number_list=[]
count=101
for i in range (0,no_of_passengers):
src=source[0:3]
des=destination[0:3]
ticket_number_list.append(airline+":"+src+":"+des+":"+str(count))
count+=1
if(no_of_passengers<5):
return ticket_number_list
else:
return ticket_number_list[-5:]
#Provide different values for airline,source,destination,no_of_passengers and test your program
print(generate_ticket("AI","Bangalore","London",7))