For this MSP, your program will prompt the user to enter city/state pairs. You should build a
Question:
For this MSP, your program will prompt the user to enter city/state pairs. You should build a dictionary of these city/state pairs, using the city as the key and the state as the value.
You don't know how many city/state pairs there will be, so will want to use a loop to enter the city/state pairs.
Prompt the user for a city or the word quit. If the user enters quit, the looping should end and the dictionary should be printed without any formatting or the phrase No cities to list! if there were no cities entered.
Your program should only ask for a state if a valid city (i.e., not quit) was entered.
If there are key/value pairs in the dictionary, just print the dictionary as a Python dictionary; i.e., no special formatting.
A sample interaction, entering quit as the first city:
Enter a city, "quit" to end: quit
No cities to list!
Another example, entering values for Omaha, Estes Park, and St. Louis.
Enter a city, "quit" to end: Omaha
Enter a state: NE
Added Omaha, NE to dictionary!
Enter a city, "quit" to end: Estes Park
Enter a state: CO
Added Estes Park, CO to dictionary!
Enter a city, "quit" to end: St. Louis
Enter a state: Missouri
Added St. Louis, Missouri to dictionary!
Enter a city, "quit" to end: quit
There are 3 cities in the dictionary: {'Omaha': 'NE', 'Estes Park': 'CO', 'St. Louis': 'Missouri'}
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang