class LineSegment: '''A line segment from one Point to another Point.''' def __init__(self, start_point, end_point): '''Initializes the line segment by storing the start and endpoints.''' self.start_point = start_point self.end_point = end_point def slope(self): '''Return the slope of the line segment.''' change_y = self.end_point.y - self.start_point.y change_x = self.end_point.x - self.start_point.x return change_y / change_x def length(self): '''Return the length of the line segment.''' return self.start_point.distance_to(self.end_point) def __str__(self): '''Return a string version of the line segment.''' return 'Line from ' + str(self.start_point) + ' to ' + str(self.end_point) def main(): '''Test the LineSegment class.''' p1 = Point(3, 7) p2 = Point(-10, 1) line = LineSegment(p1, p2) print("line is " + str(line)) linelen = line.length() print("length of line is " + str(linelen)) lineslope = line.slope() print("slope of line is " + str(lineslope)) main()