Back to Freecodecamp

Step 16

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

latest837 B
Original Source

--description--

Create an R3Vector instance with 2, 2, and 3 as the values of x, y, and z, respectively. Assign the new instance to v2.

--hints--

You should declare a variable v2 and assign it R3Vector(2, 2, 3).

js
({ test: () => assert(runPython(`_Node(_code).find_variable("v2").is_equivalent("v2 = R3Vector(2, 2, 3)")`)) })

--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, y)
        self.z = z

v1 = R2Vector(2, 3)
print(v1.norm())
print(v1)
--fcc-editable-region--

--fcc-editable-region--