Skip to content

Commit

Permalink
implement add, subtract, multiply of vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
tclapython committed Jan 26, 2016
1 parent 3505c39 commit 066d2df
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@ def __str__(self):

def __eq__(self, v):
return self.coordinates == v.coordinates

def __ne__(self, v):
return self.coordinates != v.coordinates

def __add__(self, v):
new_coordinates = [x+y for x,y in zip(self.coordinates, v.coordinates)]
return Vector(new_coordinates)

def __sub__(self, v):
new_coordinates = [x-y for x,y in zip(self.coordinates, v.coordinates)]
return Vector(new_coordinates)

def __mul__(self, v):
new_coordinates = [x*y for x,y in zip(self.coordinates, v.coordinates)]
return Vector(new_coordinates)

0 comments on commit 066d2df

Please sign in to comment.