Question: Python Coding:The Road class For us, a road will be something that has a length and connects two different cities. Complete the implementation of the
Python Coding:The Road class For us, a road will be something that has a length and connects two different cities. Complete the implementation of the Road class by writing code for the three unfinished methods ( eq (), set length(), and str ()), following the specifications given in the comments. Test your Road methods by running test assign6.py. You should now see all of the City and Road tests pass.
class Road: """ A Road connects two different cities and has a length. """
def __init__(self, city1, city2, length): """ city1, city2: strings length: int """ # DO NOT MODIFY THIS METHOD if city1 == city2: raise ValueError("Cities must be different") self.city1 = city1 self.city2 = city2 self.length = int(length)
def __eq__(self, other): """ Two roads are considered equal if they connect the same two cities.
other: Road object returns: boolean """ return NotImplemented
def __ne__(self, other): # DO NOT MODIFY THIS METHOD return not (self == other)
def set_length(self, length): """ Sets this road's length to the given length. Does not return anything.
length: int """ return NotImplemented
def __str__(self): """ Returns a string representation of this road, of the form
returns: string """ return "Not Implemented"
def __repr__(self): # DO NOT MODIFY THIS METHOD return str(self)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
