Question: Task 1: Distance Map Requires: knowing how to design and implement a class In file distance_map.py, use the Class Design Recipe to define a class


Task 1: Distance Map Requires: knowing how to design and implement a class In file distance_map.py, use the Class Design Recipe to define a class called DistanceMap that lets client code store and look up the distance between any two cities. Your program will use an instance of this class to store the information from a map data file. If a distance from city A to city B has been stored in your distance map, then it must be capable of reporting the distance from city A to city B and of reporting the distance from city B to city A (which could be the same or different). Your class must provide a method called distance that takes two strings (the names of two cities) and returns an int which is the distance from the first city to the second, or -1 if the distance is not stored in the distance map. The doctest examples in class Fleet depend on there also being a method called add_distance. Make sure that it exists and is consistent with those doctests. The choice of data structure is up to you. For something so simple, there are surprisingly many choices. Just pick something reasonable, and be sure to define representation invariants that document any important facts about your data structure. You may find it helpful to use a default parameter somewhere in this class. Here is an example of how they work. This function takes two parameters, but if the caller sends only one argument, it uses the default value 1 for the second argument. def increase_items (lst: List[int], n: int=1) -> None: ""Mutate lst by adding n to each item. >>> grades = [80, 76, 88] >>> increase_items (grades, 5) >>> grades == [85, 81, 93] True >>> increase_items (grades) >>> grades [86, 82, 94] True == IT IT TO for i in range (len (1st)): Ist[i] += n This module contains the class Distance Map, which is used to store and look up distances between cities. This class does not read distances from the map file. (All reading from files is done in module experiment.) Instead, it provides public methods that can be called to store and look up distances. from typing import Dict class Distance Map: # TODO: Implement this class! pass if name_ == '__main__': import python_ta python_ta.check_all(config={ 'allowed-import-modules': ['doctest', 'python_ta', 'typing'], 'disable': ['E1136'], 'max-attributes': 15, }) import doctest doctest.testmod()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
