Back to Freecodecamp

Step 18

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

latest1.1 KB
Original Source

--description--

Remove the existing print calls. Then, as you did before for v1, print v2 and the value returned by v2.norm().

--hints--

You should not have print(v1) and print(v1.norm()) in your code.

js
({
    test: () => {
      assert.isFalse(runPython(`_Node(_code).has_call("print(v1)")`));
      assert.isFalse(runPython(`_Node(_code).has_call("print(v1.norm())")`));
    }
})

You should print v2 and v2.norm().

js
({
    test: () => {
      assert(runPython(`_Node(_code).has_call("print(v2)")`));
      assert(runPython(`_Node(_code).has_call("print(v2.norm())")`));
    }
})

--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}'

class R3Vector(R2Vector):
    def __init__(self, *, x, y, z):
        super().__init__(x=x, y=y)
        self.z = z
--fcc-editable-region--
v1 = R2Vector(x=2, y=3)
print(v1.norm())
print(v1)

v2 = R3Vector(x=2, y=2, z=3)
--fcc-editable-region--