input: other vector assumes: other vector has the same size returns a new vector that represents the sum.
(self, other: Vector)
| 70 | return "(" + ",".join(map(str, self.__components)) + ")" |
| 71 | |
| 72 | def __add__(self, other: Vector) -> Vector: |
| 73 | """ |
| 74 | input: other vector |
| 75 | assumes: other vector has the same size |
| 76 | returns a new vector that represents the sum. |
| 77 | """ |
| 78 | size = len(self) |
| 79 | if size == len(other): |
| 80 | result = [self.__components[i] + other.component(i) for i in range(size)] |
| 81 | return Vector(result) |
| 82 | else: |
| 83 | raise Exception("must have the same size") |
| 84 | |
| 85 | def __sub__(self, other: Vector) -> Vector: |
| 86 | """ |