From 53ffb5f4cecac5b40386ed1bf65ceb736378b292 Mon Sep 17 00:00:00 2001 From: Sven Riwoldt Date: Tue, 3 Nov 2020 12:01:45 +0100 Subject: [PATCH] =?UTF-8?q?Subtraktion=20und=20Skalarmultiplikation=20hinz?= =?UTF-8?q?ugef=C3=BCgt=20und=20getestet?= 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 a6d2317..cef3dec 100644 --- a/vector.py +++ b/vector.py @@ -25,6 +25,14 @@ class Vector(object): def plus(self,v): new_coordinates = [x+y for x,y in zip(self.coordinates, v.coordinates)] return Vector(new_coordinates) + + def minus(self,v): + new_coordinates = [x-y for x,y in zip(self.coordinates, v.coordinates)] + return Vector(new_coordinates) + + def times_scalar(self, c): + new_coordinates = [c*x for x in self.coordinates] + return Vector(new_coordinates) # Tests @@ -37,4 +45,8 @@ 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 +print vektor_1.plus(vektor_2) + +print vektor_2.minus(vektor_3) + +print vektor_3.times_scalar(3) \ No newline at end of file