code: def segments_distance(segment1, segment2):
      
      assert isinstance(segment1, LineSegment), \
          "segment1 is not a LineSegment, but a %s" % type(segment1)
      assert isinstance(segment2, LineSegment), \
          "segment2 is not a LineSegment, but a %s" % type(segment2)
      if len(get_segments_intersections(segment1, segment2)) >= 1:
          return 0
      # try each of the 4 vertices w/the other segment
      distances = []
      distances.append(point_segment_distance(segment1.p1, segment2))
      distances.append(point_segment_distance(segment1.p2, segment2))
      distances.append(point_segment_distance(segment2.p1, segment1))
      distances.append(point_segment_distance(segment2.p2, segment1))
      return min(distances)
docs: Calculate the distance between two line segments in the plane.
  
      >>> a = LineSegment(Point(1,0), Point(2,0))
      >>> b = LineSegment(Point(0,1), Point(0,2))
      >>> "%0.2f" % segments_distance(a, b)
      '1.41'
      >>> c = LineSegment(Point(0,0), Point(5,5))
      >>> d = LineSegment(Point(2,2), Point(4,4))
      >>> e = LineSegment(Point(2,2), Point(7,7))
      >>> "%0.2f" % segments_distance(c, d)
      '0.00'
      >>> "%0.2f" % segments_distance(c, e)
      '0.00'