nach python 3 gewandelt und pdb eingefügt

This commit is contained in:
2020-11-07 09:36:07 +01:00
parent 7fc75fdde3
commit aa142dbcf0

View File

@@ -1,5 +1,6 @@
# -*- coding: iso-8859-15 -* # -*- coding: iso-8859-15 -*
from math import sqrt from math import sqrt
import pdb
class Vector(object): class Vector(object):
def __init__(self, coordinates): def __init__(self, coordinates):
@@ -44,6 +45,7 @@ class Vector(object):
def magnitude(self): def magnitude(self):
#Länge #Länge
coordinates_squared = [x**2 for x in self.coordinates] coordinates_squared = [x**2 for x in self.coordinates]
pdb.set_trace()
return sqrt(sum(coordinates_squared)) return sqrt(sum(coordinates_squared))
def normalized(self): def normalized(self):
@@ -56,18 +58,18 @@ class Vector(object):
# Tests # Tests
vektor_1 = Vector([1,2,3]) vektor_1 = Vector([1,2,3])
print vektor_1 print (vektor_1)
vektor_2 = Vector([1,2,3]) vektor_2 = Vector([1,2,3])
vektor_3 = Vector([-1,2,3]) vektor_3 = Vector([-1,2,3])
print vektor_1 == vektor_2 print (vektor_1 == vektor_2)
print vektor_2 == vektor_3 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() print ("Magnitude -- Länge ", vektor_3.magnitude())