add vectors task solution
This commit is contained in:
parent
0ba836206b
commit
856f1a4e33
17
codewars/thinkful-object drills.py
Normal file
17
codewars/thinkful-object drills.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
class Vector:
|
||||||
|
def __init__(self, x, y):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
|
||||||
|
def add(self, other_vector):
|
||||||
|
new_x = self.x + other_vector.x
|
||||||
|
new_y = self.y + other_vector.y
|
||||||
|
|
||||||
|
return Vector(new_x, new_y)
|
||||||
|
|
||||||
|
|
||||||
|
def subtract(self, other_vector):
|
||||||
|
new_x = self.x - other_vector.x
|
||||||
|
new_y = self.y - other_vector.y
|
||||||
|
|
||||||
|
return Vector(new_x, new_y)
|
||||||
Loading…
x
Reference in New Issue
Block a user