From aa142dbcf0f4c36eb7c1b3bfd96500a74de20418 Mon Sep 17 00:00:00 2001 From: Sven Riwoldt Date: Sat, 7 Nov 2020 09:36:07 +0100 Subject: [PATCH] =?UTF-8?q?nach=20python=203=20gewandelt=20und=20pdb=20ein?= =?UTF-8?q?gef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vector.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/vector.py b/vector.py index 7f0b96c..1d4a943 100644 --- a/vector.py +++ b/vector.py @@ -1,5 +1,6 @@ # -*- coding: iso-8859-15 -* from math import sqrt +import pdb class Vector(object): def __init__(self, coordinates): @@ -42,32 +43,33 @@ class Vector(object): return Vector(new_coordinates) def magnitude(self): - #Länge - coordinates_squared = [x**2 for x in self.coordinates] - return sqrt(sum(coordinates_squared)) + #Länge + coordinates_squared = [x**2 for x in self.coordinates] + pdb.set_trace() + return sqrt(sum(coordinates_squared)) def normalized(self): - try: - magnitude = self.magnitude() - return self.times_scalar(1./magnitude) + try: + magnitude = self.magnitude() + return self.times_scalar(1./magnitude) except ZeroDivisonError: raise Exception('Ein Null-Vektor kann nicht normalisiert werden') # Tests vektor_1 = Vector([1,2,3]) -print vektor_1 +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 == vektor_2) +print (vektor_2 == vektor_3) -print vektor_1.plus(vektor_2) +print (vektor_1.plus(vektor_2)) -print vektor_2.minus(vektor_3) +print (vektor_2.minus(vektor_3)) -print vektor_3.times_scalar(3) +print (vektor_3.times_scalar(3)) -print "Magnitude -- Länge ", vektor_3.magnitude() \ No newline at end of file +print ("Magnitude -- Länge ", vektor_3.magnitude()) \ No newline at end of file