0
Error _add_ Vector3D
Hello community I don't understand why this code doesn't work someone help class Vector3D: def __init__(self, x, y, z): self.x = x self.y = y self.z = z def __add__(self, other, another): return Vector3D(self.x + other.x + another.x, self.y + other.y + another.y, self.z + other.z + another.z) first = Vector3D(5, 7, 2) second = Vector3D(3, 9, 3) third = Vector3D(5, 6, 4) result = first + second + third print('x=', result.x) print('y=', result.y) print('z=', result.z)
1 Answer
0
__add__
is a methode you only can override.
delete another and everything will work as expected, because the + calls the __add__ methods each time!
or let me rephrase it, first two vectors will added together, and the result with the third one.
does this help?