The following code is used by an airline company for their passenger management system. The code asks the user to select among the following options and then performs the required task:
add: Asks the user to enter a name and destination (from a list), then adds that customer to a passenger list (i.e. passengers)
del: Asks the user to enter a name and deletes the first occurrence of the customer to a passenger list (i.e. passengers)
find: Asks the user to enter a name and finds all the occurrence of the customer to a passenger list (i.e. passengers). Then prints the name and destination for that passenger in a tabular format (see the output table format)
print: Prints the name and destination values for all passengers in a tabular format (see the output table format)
exit: Exit from the program
The information (i.e. name and destination) regarding the passengers are stored in the passengers list. Each item in this list is also a list where the first item is the name of the passenger and the second item is the destination.
Your Task:
Due to the new requirement, you must change the Del task such that it takes the name of a passenger as input and deletes all occurrences of the passenger from the passengers list. The program also prints the number of occurrences removed from the passengers list. Write the python code to implement this functionality between the green # lines. i.e.
######################################################
######################################################
Hint:
Removed <n> occurrences of <name>
Output table format:
———————————————
|Passenger Name | Destination |
———————————————
|A | PHX |
|B | AUS |
|F | LAS |
|A | AUS |
|B | LAS |
|C | PHX |
|A | PHX |
———————————————
Sample Input:
For the passengers given in the above table
Enter passenger name:
A
Sample Output:
Removed 3 occurrences of A
The table after deletion:
———————————————
|Passenger Name | Destination |
———————————————
|B | AUS |
|F | LAS |
|B | LAS |
|C | PHX |
———————————————
Code:
menu_prompt = ”’
Available commands:n
(add) Add passengern
(del) Delete passengern
(find) Find passenger n
(print) Print passenger listn
(exit) Exit the programn
Enter command:n”’
destinations = [‘PHX’, ‘AUS’, ‘LAS’]
destination_prompt = ”’
Available destinations:n
(PHX) Phoenixn
(AUS) Austinn
(LAS) Las Vegasn
Enter destination:n”’
passengers = []
print(‘Welcome to Mohawk Airlines!’)
while True:
user_input = input(menu_prompt).strip().lower()
if user_input == ‘add’:
name = input(‘Enter passenger name:n’).strip().upper()
destination = input(destination_prompt).strip().upper()
while destination not in destinations:
destination = input(destination_prompt).strip().upper()
passengers.append([name, destination])
elif user_input == ‘del’:
name = input(‘Enter passenger name:n’).strip().upper()
# deletes only the first appearance
# for index, row in enumerate(passengers):
# if row[0] == name: # as the first entry is the name
# del passengers[index]
# break
######################################################
############# Code implementing the steps ################
######################################################
elif user_input == ‘find’:
name = input(‘Enter passenger name:n’).strip().upper()
foundindex = []
for index, row in enumerate(passengers):
if row[0] == name:
foundindex.append(index)
if len(foundindex) == 0:
print(“No such customer”)
else:
print(“———————————————“)
print(“|Passenger Name | Destination |”)
print(“———————————————“)
for index in foundindex:
print(‘|{0:20} | {1:20}|’.format(passengers[index][0], passengers[index][1]))
print(“———————————————“)
elif user_input == ‘print’:
print(“———————————————“)
print(“|Passenger Name | Destination |”)
print(“———————————————“)
for passenger in passengers:
print(‘|{0:20} | {1:20}|’.format(passenger[0], passenger[1]))
print(“———————————————“)
elif user_input == ‘exit’:
break
else:
print(‘Unrecognized command.’)
######################################################
########### Your function code goes here. #################
######################################################
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more