Learn Special Methods by Building a Vector Space - Step 8

Tell us what’s happening:

hi ,guys! I can’t fix this. when I write like this, it returns the ‘norm’ is not defined. but if I put 4 blank space in the front, it returns ‘indentation error’. please help me! thanks!

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(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/127.0.0.0 Safari/537.36 Edg/127.0.0.0

Challenge Information:

Learn Special Methods by Building a Vector Space - Step 8

norm is an object method, so you’ll need to reference the object first, like this:

object.method()

You’ve instantiated an object called v1

1 Like