Question: PYTHON In this exercise you practice adding and removing elements from a dict. A dict called stateAbbrs has been initialized to an empty dict ({}).
PYTHON
In this exercise you practice adding and removing elements from a dict. A dict called stateAbbrs has been initialized to an empty dict ({}). It will contain pairs where the key is the state name and the value is the state abbreviation.
(1) Prompt user for a state name and the corresponding state abbreviation and add the pair state name/ state abbreviation to the dict stateAbbrs. Print the dict using the statement print(stateAbbrs). Sample input and corresponding output are shown below.
The input:
Alabama AL
gives the output:
Enter state name: State abbreviation: {'Alabama': 'AL'} (2) Prompt user for another state name and the corresponding state abbreviation and add the pair state name/ state abbreviation to the dict stateAbbrs. Print the dict using the statement print(stateAbbrs).Sample input and corresponding output are shown below.
The input:
Alabama AL Georgia GA
gives the output:
Enter state name: Enter state abbreviation: {'Alabama': 'AL'} Enter state name: Enter state abbreviation: {'Alabama': 'AL', 'Georgia': 'GA'} OR {'Georgia': 'GA', 'Alabama': 'AL'} (3) Delete from the dict the information about the second state that was entered and print the dict. Print the dict using the statement print(stateAbbrs).Sample input and corresponding output are shown below. The input:
Alabama AL Georgia GA
gives the output:
Enter state name: Enter state abbreviation: {'Alabama': 'AL'} Enter state name: Enter state abbreviation: {'Alabama': 'AL', 'Georgia': 'GA'} OR {'Georgia': 'GA', 'Alabama': 'AL'} {'Alabama': 'AL'}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
