Define classVectorfor n-dimensional vectors as follows:
Vector
Vector(l)
len(l)
l
TypeError
int
float
v.dim()
v. __getitem__(i)
i
1
IndexError
v. __setitem__(i, x)
v
x
v.__str__()
v. __add__(other)
ValueError
other
v.__mul__(other)
AssertionError
v.__rmul__(other)
Python uses following equivalent notations:
v[i] = v.__getitem__(i) v[i] = x = v.__setitem__(i, x) str(v) = v.__str__() v + other = v.__add__(other) v * other = v.__mul__(other) other * v = v.__rmul__(other) if other.__mul__(v) is not defined
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here