Question: The example program below shows how the above methods might be used to store passenger names and travel destinations in a database. The use of

The example program below shows how the above methods might be used to store passenger names and travel destinations in a database. The use of strip(), lower(), and upper() standardize user-input for easy comparison.
Run the program below and add some passengers into the database. Add a duplicate passenger name, using different capitalization, and print the list again.
menu_prompt =('Available commands:
'
'(add) Add passenger
'
'(del) Delete passenger
'
'(print) Print passenger list
'
'(exit) Exit the program
'
'Enter command:
')
destinations =['PHX', 'AUS', 'LAS']
destination_prompt =('Available destinations:
'
'(PHX) Phoenix
'
'(AUS) Austin
'
'(LAS) Las Vegas
'
'Enter destination:
')
passengers ={}
print('Welcome to Mohawk Airlines!
')
user_input = input(menu_prompt).strip().lower()
while user_input != 'exit':
if user_input == 'add':
name = input('Enter passenger name:
').strip().upper()
destination = input(destination_prompt).strip().upper()
if destination not in destinations:
print('Unknown destination.
')
else:
passengers[name]= destination
elif user_input == 'del':
name = input('Enter passenger name:
').strip().upper()
if name in passengers:
del passengers[name]
elif user_input == 'print':
for passenger in passengers:
print('{}-->{}'.format(passenger.title(), passengers[passenger]))
else:
print('Unrecognized command.')
user_input = input('Enter command:
').strip().lower()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!