From e3aad40d1ddd9eaec265b42fbb1e09c0e6b9f1d6 Mon Sep 17 00:00:00 2001 From: Pascal Lais Date: Tue, 10 Mar 2020 08:35:45 +0100 Subject: [PATCH] Update point.py Remove type checking and make an overwritten operator from method str() --- point.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/point.py b/point.py index 1935ae4..6a7a701 100644 --- a/point.py +++ b/point.py @@ -11,27 +11,17 @@ class Point(): self.set_y(y) def set_x(self, new_x): """Set the X-Coordinate of the Point""" - if int == type(new_x): - self.__x = new_x - elif float == type(new_x): - self.__x = int(new_x) - else: - raise Exception(self, "Type of x has to be int") + self.__x = int(new_x) def get_x(self): """Returns the X-Coordinate of the Point""" return self.__x def set_y(self, new_y): """Set the Y-Coordinate of the Point""" - if int == type(new_y): - self.__y = new_y - elif float == type(new_y): - self.__y = int(new_y) - else: - raise Exception(self, "Type of y has to be int") + self.__y = new_y def get_y(self): """Returns the Y-Coordinate of the Point""" return self.__y - def str(self): + def __str__(self): """Returns the coordinates as a string""" return "(" + str(self.get_x()) + "/" + str(self.get_y()) + ")" def draw(self):