given a list of string containing flight tickets.the pattern of the each string in the list is
'source:destination:flight_id:ticket_no' write a python function to return a list of strings containing passenger count of each flight in the format"flight_id:no_of_passengers"
Answers
Our output format should be looking like this:
source : destination : flight_id : ticket_no
To get the source, destination, flight id and ticket number, we will need to take an input from the user first and then display them.
There are two ways you can print the tickets.
(1) Print all the tickets in one column
(2) Print all the tickets in one row separated by ';'.
___________________________________________________
This is how we take the input for the source, destination and flight id and number of passengers
source, destination,flight_id,pas = input('Source:'),input('Destination:'),input('Flight ID:'),int(input('Total number of passengers'))____________________________________________________
Now we have all the inputs we need and the only thing that is left is to print out all these tickets.
Here are the two ways:
____________________________________________________
CODE 1:
source, destination,flight_id,pas = input('Source:'),input('Destination:'),input('Flight ID:'),int(input('Total number of passengers'))
print(*[f'{source}:{destination}:{flight_id}:{i}' for i in range(1,pas+1)],sep = '\n')
Output if pas = 10, source = chennai, destination = bangalore and flight id = Indigo 5232
chennai:delhi:Indigo 5232:1
chennai:delhi:Indigo 5232:2
chennai:delhi:Indigo 5232:3
chennai:delhi:Indigo 5232:4
chennai:delhi:Indigo 5232:5
chennai:delhi:Indigo 5232:6
chennai:delhi:Indigo 5232:7
chennai:delhi:Indigo 5232:8
chennai:delhi:Indigo 5232:9
chennai:delhi:Indigo 5232:10
__________________________________________________
CODE 2:
source, destination,flight_id,pas = input('Source:'),input('Destination:'),input('Flight ID:'),int(input('Total number of passengers'))
print(*[f'{source}:{destination}:{flight_id}:{i}' for i in range(1,pas+1)],sep = ' ; ')
Output if pas = 10, source = chennai, destination = bangalore and flight id = Indigo 5232
chennai:delhi:Indigo 5232:1 ; chennai:delhi:Indigo 5232:2 ; chennai:delhi:Indigo 5232:3 ; chennai:delhi:Indigo 5232:4 ; chennai:delhi:Indigo 5232:5 ; chennai:delhi:Indigo 5232:6 ; chennai:delhi:Indigo 5232:7 ; chennai:delhi:Indigo 5232:8 ; chennai:delhi:Indigo 5232:9 ; chennai:delhi:Indigo 5232:10
___________________________________________________