$40
This laboratory exercise has two primary learning goals. First, the exercise will provide you with an opportunity to practice your skills for Python program generation in the PyCharm integrated development environment (IDE) that will be used throughout this course. In this way, this exercise will provide practice in some of the fundamental skills that will be needed to successfully complete future programming assignments. Second, this exercise will give you an opportunity to assess your preparation for future assignments. This exercise should be easy for you. If you do not find it fairly easy, then you should contact the instructor to discuss the possibility that you are not yet prepared to successfully complete the course programming assignments. Future programming assignments will be much more difficult.
In this exercise, you will be given Python code that implements a road map data structure. You are required to implement one method for this data structure which calculates the total path cost (e.g., travel time) for a given path on the map..
1
Activities
You are to provide a Python function that calculates the path cost (e.g., travel time) of a path through a given road map. Your provided Python source code must be compatible with the provided Python utility code which implements simple road maps. You should not modify provided source code files except to implement the body of the required path cost function.
More specifically, you are to provide a function called pathcost in a source code file named “map.py”. This function is a method on the provided RoadMap class. Your function should have the following features ...
• takes two arguments beyond the RoadMap object:
1. start — a symbolic name for the starting location for the path of interest
2. roadlist — a Python list of symbolic road segment names, describing the path to be taken from the starting location
• returns the sum of the costs of the listed road segments, as recorded in the RoadMap object
• returns zero if the arguments do not describe a valid path through the map which is encoded in the RoadMap object
In general, your function should allow the provided “main.py” script to output correct solutions for any path through any map encoded as a RoadMap object. The function that you implement should write no output, as this will clutter the output produced by the “main.py” script. If you include any statements that write output in your code (perhaps as tools for debugging) these should be removed prior to completion of your solution.
The Python utility code that you are required to use is provided in a ZIP archive file called “EX1.zip” which is available in the “Files” section of the class CatCourses site, under “Laboratory Exercise #1”. This utility code provides a class which encodes a simple road map, involving locations connected by road segments. Each location has a name and coordinates, which can be conceived as longitude and latitude. Each road segment represents a one-way connection from one location to another. Each road segment has a name and a cost of traversal. The contents of these utility files will be discussed during a laboratory session, and comments in these files should assist in your understanding of the provided code. Questions are welcome, however, and should be directed to the teaching team.
The provided “main.py” script includes an example map, which you may use to perform initial tests of your code. It is important that your function performs correctly when given any possible map, however, so your code should be tested on additional maps of your own design that potentially contain unusual features. It is possible for your code to contain serious errors but still perform well when using the single provided test case.