Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python 3 1. Here is a dictionary of countries and their capitals: capitals ('Afghanistan': 'Kabul, United States of America': Washington D.c, Ukraine: Kyiv', Morocco: Rabat'
Python 3
1. Here is a dictionary of countries and their capitals: capitals ('Afghanistan': 'Kabul, United States of America': Washington D.c, Ukraine: Kyiv', Morocco: Rabat' Why is it appropriate to use a dictionary in this scenario? What are the keys? What are the values? 2. When capitals is defined as above, what will be printed when this code is run? for item in capitals printlitem) 3. Change the code so both the key' and 'value' are printed (ie. print the country as well as the city in the loop). Give the variables more descriptive names than item Write code to add to the capitals dictionary a new capital for a country in which you grew up, have visited, or want to visit. 4. Add code to ask the user for a country. If the country is already in the 'capitals dictionary, print out its capital. If it is not, display Capsital not found 5. 6. Change your program so after the user inputs a country, if it is not in the 'capitals dictionary, ask the user for the capital of that new country. Update the dictionary with the user inputted country and capital then print the updated dictionary, each pair on one line
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started