Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program that will read in the countries and their capitals from the countryCap.txt file. Look at the file. It is a comma-delimited

Write a Python program that will read in the countries and their capitals from the countryCap.txt file. Look at the file. It is a comma-delimited file (comma between country and capital). You will need to get a line from the .txt file, split the line into a country and a capital (remember that the split method returns a list) and then store them in a dictionary. (As you recall from Chapter 8, a dictionary has a key/value pair. The key can be the country name, and the value can be the capital name.) Once all data from the text file has been stored in the dictionary, allow the user to enter the name of a country, then find the capital and display it to the user. Loop back up and let them enter another country until they enter a value of x to stop the loop. Make sure to handle the following exceptions if the users country name is not found in the dictionary, or if the countryCap.txt file is not found when you try to open it. You will need to create two functions one called fillDictionary() and one called findCapital(). Pass the appropriate data using a parameter list. Do not use global variables.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions