49.4k views
4 votes
) Python command line menu-driven application that allows a user to display, sort and update, as needed a List of U.S states containing the state capital, overall state population, and state flower. The Internet provides multiple references with these lists. For example:

User Ogun
by
3.2k points

1 Answer

1 vote

Answer:

Step-by-step explanation:

The following is a Python program that creates a menu as requestes. The menu allows the user to choose to display list, sort list, update list, and/or exit. A starting list of three states has been added. The menu is on a while loop that keeps asking the user for an option until exit is chosen. A sample output is shown in the attached picture below.

states = {'NJ': ['Trenton', 8.882, 'Common blue violet'], 'Florida':['Tallahassee', 21.48, 'Orange blossom'], 'California': ['Sacramento', 39.51, 'California Poppy']}

while True:

answer = input('Menu: \\1: display list\\2: Sort list\\3: update list\\4: Exit')

print(type(answer))

if answer == '1':

for x in states:

print(x, states[x])

elif answer == '2':

sortList = sorted(states)

sorted_states = {}

for state in sortList:

sorted_states[state] = states[state]

states.clear()

states = sorted_states

sorted_states = {}

elif answer == '3':

state = input('Enter State: ')

capital = input('Enter Capital: ')

population = input('Enter population: ')

flower = input('Enter State Flower: ')

states[state] = [capital, population, flower]

else:

break

) Python command line menu-driven application that allows a user to display, sort-example-1
User Johnna
by
3.4k points