From e0e4c99bfae51159f25316d38cdcd0cc9185233f Mon Sep 17 00:00:00 2001 From: Sven Riwoldt Date: Tue, 3 Nov 2020 09:31:56 +0100 Subject: [PATCH] =?UTF-8?q?Vektoraddtion=20hinzugef=C3=BCgt=20und=20getest?= =?UTF-8?q?et?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vector.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/vector.py b/vector.py index a7fb54d..a6d2317 100644 --- a/vector.py +++ b/vector.py @@ -21,8 +21,20 @@ class Vector(object): def __eq__(self, v): return self.coordinates == v.coordinates + + def plus(self,v): + new_coordinates = [x+y for x,y in zip(self.coordinates, v.coordinates)] + return Vector(new_coordinates) # Tests vektor_1 = Vector([1,2,3]) -print vektor_1 \ No newline at end of file +print vektor_1 + +vektor_2 = Vector([1,2,3]) +vektor_3 = Vector([-1,2,3]) + +print vektor_1 == vektor_2 +print vektor_2 == vektor_3 + +print vektor_1.plus(vektor_2) \ No newline at end of file