diff --git a/uebung_05/exercise_03/.exercise_03.py.swp b/uebung_05/exercise_03/.exercise_03.py.swp deleted file mode 100644 index 06bd1b1..0000000 Binary files a/uebung_05/exercise_03/.exercise_03.py.swp and /dev/null differ diff --git a/uebung_05/exercise_03/exercise_03.py b/uebung_05/exercise_03/exercise_03.py index 53fcd5e..5f771c3 100644 --- a/uebung_05/exercise_03/exercise_03.py +++ b/uebung_05/exercise_03/exercise_03.py @@ -16,9 +16,6 @@ class Point: return Point(-self.__x__, -self.__y__) def __add__(self, other): - x = 0.0 - y = 0.0 - if isinstance(other, Point): return Point(self.__x__ + other.__x__, self.__y__ + other.__y__) elif isinstance(other, int) or isinstance(other, float): @@ -30,10 +27,7 @@ class Point: return self + other def __sub__(self, other): - if isinstance(other, Point) or isinstance(other, int) or isinstance(other, float): - return self + (-other) - else: - raise ValueError("Operand must be Point, int or float.") + return self + (-other) def __rsub__(self, other): return self - other @@ -66,14 +60,15 @@ p3 = Point (3, 2) p4 = 2 * p2 + p3 - 1 p5 = p4.rot(math.pi / 2) -plt.plot(p1.get_x(), p1.get_y(), "orange", marker = "o") -plt.plot(p2.get_x(), p2.get_y(), "green", marker = "o") -plt.plot(p3.get_x(), p3.get_y(), "yellow", marker = "o") -plt.plot(p4.get_x(), p4.get_y(), "purple", marker = "o") -plt.plot(p5.get_x(), p5.get_y(), "purple", marker = "o") +plt.plot(p1.get_x(), p1.get_y(), "orange", marker = "o", label = p1) +plt.plot(p2.get_x(), p2.get_y(), "green", marker = "o", label = p2) +plt.plot(p3.get_x(), p3.get_y(), "yellow", marker = "o", label = p3) +plt.plot(p4.get_x(), p4.get_y(), "purple", marker = "o", label = 2 * p2 + p3 - 1) +plt.plot(p5.get_x(), p5.get_y(), "purple", marker = "o", label = f"{p4} rotated 90°") plt.title("Points") plt.xlabel("x") plt.ylabel("y") +plt.legend() plt.show()