Write a function code and implement it

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
  • del
  • find
  • print
  • exit

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:

  1. Create an empty list foundindex.
  2. Iterate over the passengers list. If the name value of a item is same as the input name, append the index of the row to the foundindex list.
  3. If the number of items in the foundindex list is greater than 0, do the following. Else, do nothing.
    1. Iterate over the foundindex list using index, i.
      1. Delete the row foundindex[i] from the passengers list
      2. Update foundindex by subtracting 1 from all the values in the list. Write a function to implement this. This function will take a list as a parameter and return a list where the numbers are reduced by 1. (This code will go between the next green # lines that says your function code goes here.)
  4. Display the number of occurrences removed for the name. Output string format:

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. #################

######################################################

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

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.

Money-back guarantee

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 more

Zero-plagiarism guarantee

Each 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 more

Free-revision policy

Thanks 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 more

Privacy policy

Your 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 more

Fair-cooperation guarantee

By 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
error: Content is protected !!
Open chat
1
You can contact our live agent via WhatsApp! Via + 1 (929) 473-0077

Feel free to ask questions, clarifications, or discounts available when placing an order.

Order your essay today and save 20% with the discount code SCORE