Back to Freecodecamp

Step 13

curriculum/challenges/english/blocks/learn-special-methods-by-building-a-vector-space/65f40401e6ef53173c04e27d.md

latest966 B
Original Source

--description--

Within your new class, declare an __init__ method. Give it self, x, y, and z as the parameters.

--hints--

You should define an __init__ method inside your R3Vector class.

js
({
    test: () => assert(runPython(`
      _Node(_code).find_class("R3Vector").has_function("__init__")
    `))
})

Your __init__ method should have four parameters self, x, y, and z.

js
({
    test: () => assert(runPython(`
      _Node(_code).find_class("R3Vector").find_function("__init__").has_args("self, x, y, z")
    `))
})

--seed--

--seed-contents--

py
class R2Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        
    def norm(self):
        return (self.x**2 + self.y**2)**0.5
        
    def __str__(self):
        return f'{self.x, self.y}'
--fcc-editable-region--
class R3Vector(R2Vector):
    pass
--fcc-editable-region--
v1 = R2Vector(2, 3)
print(v1.norm())
print(v1)