Back to Freecodecamp

Step 15

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

latest799 B
Original Source

--description--

Now, you need to assign z to the z attribute of your R3Vector object.

--hints--

You should assign z to self.z after the super call.

js
({
    test: () => assert(runPython(`
      _Node(_code).find_class("R3Vector").find_function("__init__").is_ordered("super().__init__(x, y)", "self.z = 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):
    def __init__(self, x, y, z):
        super().__init__(x, y)
--fcc-editable-region--
v1 = R2Vector(2, 3)
print(v1.norm())
print(v1)