Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.
# Your solution may ONLY use the python modules listed below import math import random import string import collections import datetime import re import time import copy # YOUR CODE BELOW... def loadDataIntoDictionary(fn) : your code here... # end def def computeDistance(table, cityFrom, cityTo) : your code here... # end def def main( ) : table = loadDataIntoDictionary("cities.info") computeDistance(table, "toronto", "stuttgart") computeDistance(table, "London", "Zurich") computeDistance(table, "pARis", "VIENNA") computeDistance(table, "toronto", "TORONTO") computeDistance(table, "toronto", "Seoul") computeDistance(table, "tokyo", "San francisco") # end main( ) if __name__ == "__main__" : main( ) The OUTPUT should be EXACTLY as displayed below: 12 city records loaded... distance from Toronto, Canada to Stuttgart, Germany is: 6378.285 km ERROR... one or more city names NOT found! distance from Paris, France to Vienna, Austria is: 916.164 km distance from Toronto, Canada to Toronto, Canada is: 0.000 km ERROR... one or more city names NOT found! distance from Tokyo, Japan to San Francisco, United States is: 6701.629 km 

image text in transcribed

so this is the file the question refers to which needs to be created.

The file "cities.info" (see below) cont and the distance in Km from the city of The file is in the following format: CITY:COUNTRY:DISTANCE A where each field is separated from other The file format will always be the same itself many contain ANY number of record 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 abou the city of Toronto (i.e. Melbourne is

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

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago