Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SPECIFICATIONS: The file cities.info (see below) contains city names, countries, and the distance in Km from the city of Toronto. The file is in the

SPECIFICATIONS: The file "cities.info" (see below) contains city names, countries, and the distance in Km from the city of Toronto. The file is in the following format: CITY:COUNTRY:DISTANCE where each field is separated from other fields by the ':' character. The file format will always be the same for all records, but the file itself many contain ANY number of records. file: cities.info ========================================== Toronto:Canada:0.000 Melbourne:Australia:16267.128 San Francisco:United States:3643.327 Tokyo:Japan:10344.956 Paris:France:6000.842 London:United Kingdom:5713.099 Stuttgart:Germany:6378.285 Vancouver:Canada:3358.600 Vienna:Austria:6917.006 New York:United States:550.272 Rome:Italy:7080.692 Shanghai:China:11423.028 NOTE: For ALL the distances in the file above, the values are relative to the city of Toronto (i.e. Melbourne is 16267.128 km from Toronto, and Paris is 6000.842 km from Toronto)! Also, the city and country names in the file will ALWAYS be specified with an initial capital letter. PART A: Write the code for a Python function with the following prototype: def loadDataIntoDictionary(fn) :  This function accepts the name of a file as a parameter 'fn' and loads the data in the file into a dictionary where the city is the key and the country and distance are stored as values. How the values are stored for each key will be up to you! This function displays the number of records loaded from the file as: n city records loaded... (where n is the number of records in the file) and then returns the loaded dictionary. If the file is not found, then the error message: ERROR... file data could not be loaded is displayed and the program terminates! NOTE: You MUST use Python exception handling to manage this error and program functionality. The correct file WILL BE available on the server when submitting your solution.

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions