I am following the instructions, the value is displayed, but the error is:
You should call norm() on v1 and print the result.
Which am doing, but still doesn’t pass.
What am I missing?
Please review your instructions, as the may be wrong with the answer.
Your code so far
# User Editable Region
class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
def norm(self):
return (self.x**2 + self.y**2)**0.5
v1 = Vector(2, 3)
print(Vector.norm(v1))
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Learn Special Methods by Building a Vector Space - Step 8
The right value is printed, but using different syntax.
For example:
class A:
def method(self):
print("a")
a = A()
To call method, there are at least two ways. self in the signature of the method is an instance of the class. When calling it via class, the instance needs to be passed explicitly:
A.method(a) # a
However, when calling it via instance:
a.method() # a
The instance will be automatically passed as first argument.
While both will result in the same, the calling methods via instance is preferred.