Skip to content

Instantly share code, notes, and snippets.

@jatinsharrma
Created July 13, 2019 16:01
Show Gist options
  • Select an option

  • Save jatinsharrma/20e6619e9c2f485781403ff2601ff10f to your computer and use it in GitHub Desktop.

Select an option

Save jatinsharrma/20e6619e9c2f485781403ff2601ff10f to your computer and use it in GitHub Desktop.
Write a python program to generate the ticket numbers for specified number of passengers traveling in a flight.
# 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 :
# 1. Consider AI as the value for airline
# 2. src and dest should be the first three characters of the source and destination cities.
# 3. 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.
def generate_ticket(airline,source,destination,no_of_passengers):
ticket_number_list = []
i = 0
if no_of_passengers < 5:
while no_of_passengers != 0:
ticket_number_list.append(airline + ":" + source[:3] + ":" + destination[:3] + ":" + str(101+i))
i = i+1
no_of_passengers = no_of_passengers - 1
else:
for i in range(5):
ticket_number_list.append(airline + ":" + source[:3] + ":" + destination[:3] + ":" + str(100+no_of_passengers))
i = i+1
no_of_passengers = no_of_passengers - 1
ticket_number_list = ticket_number_list[::-1]
return ticket_number_list
#Provide different values for airline,source,destination,no_of_passengers and test your program
print(generate_ticket("AI","Bangalore","London",7))
@Deepadixit98

Copy link
Copy Markdown

I liked the code. It is very helpful for me. Thank you

@domingopr

Copy link
Copy Markdown

Thanks, I was looking at how to create a key for reconciliation data; this code , allows me to generate some ideas

@DikshaChandra

Copy link
Copy Markdown

Glad, found a different approach for this question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment