Computer Science, asked by bkharathik, 1 year ago

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.
Sample Input Expected Output
airline = AI
source = Bangalore
destination = London
no_of_passengers = 10
output= ['AI:Ban:Lon:106', 'AI:Ban:Lon:107', 'AI:Ban:Lon:108', 'AI:Ban:Lon:109', 'AI:Ban:Lon:110']
airline = BA
source = Australia
destination = France
no_of_passengers = 2
output= ['BA:Aus:Fra:101', 'BA:Aus:Fra:102']

Answers

Answered by kritika2304
0

L = [('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'E'), ('E', 'F'), ('F', 'G'), ('G', 'H'), ('H', 'I')]

# Note: the input L should normally be shuffled.

def getDepartureArrival(L):

sources, destinations = zip(*L)

sources = set(sources)

destinations = set(destinations)

for s in sources:

if s not in destinations:

depart = s

break

for d in destinations:

if d not in sources:

arriv = d

break

return depart, arriv

#

def getTrip(H):

trip = [depart]

k = depart

while k != arriv:

k = H[k]

trip.append(k)

return trip

#

depart, arriv = getDepartureArrival(L)

H = {s:d for (s,d) in L}

print getTrip(H)

I would like to know if it is possible to have a clearer and more compact Python code than the one I wrote with more than 4 consecutive loops.

share improve this question

asked

Jan 6 '17 at 17:37

eLearner

8●3 edited

May 23 '17 at 12:40

Community♦

1

Similar questions