From 4a483b939aa910273cf812558a5c02f88a145b0b Mon Sep 17 00:00:00 2001 From: Pascal Lais Date: Mon, 9 Mar 2020 07:49:10 +0100 Subject: [PATCH] Add method str to linesegment The method str returns the line segment coordinates as string. --- linesegment.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/linesegment.py b/linesegment.py index e81448c..b7a6538 100644 --- a/linesegment.py +++ b/linesegment.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -"""The linesegment module defines the class line_segment""" +"""The linesegment module defines the class line_segment.""" import point @@ -12,14 +12,14 @@ class LineSegment: self.set_endpoint(endpoint) def set_startpoint(self, new_startpoint): """Set or change the startpoint of the line segment. If not a Point object is given - the startpoint gets set to a default value of Point(0,0)""" + the startpoint gets set to a default value of Point(0,0).""" self.__startpoint = new_startpoint def get_startpoint(self): """Returns the current startpoint""" return self.__startpoint def set_endpoint(self, new_endpoint): """Set or change the endpoint of the line segment. If not a Point object is given - the endpoint gets set to a default value of Point(0,0)""" + the endpoint gets set to a default value of Point(0,0).""" self.__endpoint = new_endpoint def get_endpoint(self): """Returns the current endpoint""" @@ -29,5 +29,8 @@ class LineSegment: diff_x = abs(self.__startpoint.get_x() - self.__endpoint.get_x()) diff_y = abs(self.__startpoint.get_y() - self.__endpoint.get_y()) return ((diff_x ** 2) + (diff_y ** 2)) ** (1/2.0) + def str(self): + """Return the line segment values as string.""" + return self.__startpoint.str() + "-->" + self.__endpoint.str() def draw(self): - """TODO: Draw the line segment in a canvas""" + """TODO: Draw the line segment in a canvas."""