Subtraktion und Skalarmultiplikation hinzugefügt und getestet
This commit is contained in:
14
vector.py
14
vector.py
@@ -25,6 +25,14 @@ class Vector(object):
|
|||||||
def plus(self,v):
|
def plus(self,v):
|
||||||
new_coordinates = [x+y for x,y in zip(self.coordinates, v.coordinates)]
|
new_coordinates = [x+y for x,y in zip(self.coordinates, v.coordinates)]
|
||||||
return Vector(new_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
|
# Tests
|
||||||
|
|
||||||
@@ -37,4 +45,8 @@ 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_3.times_scalar(3)
|
||||||
Reference in New Issue
Block a user