We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d366bd commit 45757daCopy full SHA for 45757da
exercises/vector/solution/vector.py
@@ -61,15 +61,12 @@ def __neg__(self):
61
62
def __add__(self, other):
63
try:
64
- if len(self) != len(other):
65
- raise ValueError('Only vectors of same length may be added.')
66
- return Vector(a + b for a, b in zip(self, other))
+ other = Vector(other)
67
except TypeError:
68
return NotImplemented
+ if len(self) != len(other):
+ raise ValueError('vectors must have same length for addition')
69
+ return Vector(a + b for a, b in zip(self, other))
70
71
def __radd__(self, other):
72
return self + other
-
73
74
75
0 commit comments