Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!