Update point.py
Remove type checking and make an overwritten operator from method str()
This commit is contained in:
12
point.py
12
point.py
@@ -11,27 +11,17 @@ class Point():
|
|||||||
self.set_y(y)
|
self.set_y(y)
|
||||||
def set_x(self, new_x):
|
def set_x(self, new_x):
|
||||||
"""Set the X-Coordinate of the Point"""
|
"""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)
|
self.__x = int(new_x)
|
||||||
else:
|
|
||||||
raise Exception(self, "Type of x has to be int")
|
|
||||||
def get_x(self):
|
def get_x(self):
|
||||||
"""Returns the X-Coordinate of the Point"""
|
"""Returns the X-Coordinate of the Point"""
|
||||||
return self.__x
|
return self.__x
|
||||||
def set_y(self, new_y):
|
def set_y(self, new_y):
|
||||||
"""Set the Y-Coordinate of the Point"""
|
"""Set the Y-Coordinate of the Point"""
|
||||||
if int == type(new_y):
|
|
||||||
self.__y = 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")
|
|
||||||
def get_y(self):
|
def get_y(self):
|
||||||
"""Returns the Y-Coordinate of the Point"""
|
"""Returns the Y-Coordinate of the Point"""
|
||||||
return self.__y
|
return self.__y
|
||||||
def str(self):
|
def __str__(self):
|
||||||
"""Returns the coordinates as a string"""
|
"""Returns the coordinates as a string"""
|
||||||
return "(" + str(self.get_x()) + "/" + str(self.get_y()) + ")"
|
return "(" + str(self.get_x()) + "/" + str(self.get_y()) + ")"
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user