Back to Freecodecamp

Step 25

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

latest947 B
Original Source

--description--

Finally, pass the tuple() call as the argument to the str() function.

--hints--

You should pass the tuple() call you are currently returning from the __str__ method to the str() function.

js
({ test: () => assert(runPython(`_Node(_code).find_class("R2Vector").find_function("__str__").has_return("str(tuple(getattr(self, i) for i in vars(self)))")`)) })

--seed--

--seed-contents--

py

class R2Vector:
    def __init__(self, *, x, y):
        self.x = x
        self.y = y

    def norm(self):
        return sum(val**2 for val in vars(self).values())**0.5
--fcc-editable-region--
    def __str__(self):
        return tuple(getattr(self, i) for i in vars(self))
--fcc-editable-region--
class R3Vector(R2Vector):
    def __init__(self, *, x, y, z):
        super().__init__(x=x, y=y)
        self.z = z

v1 = R2Vector(x=2, y=3)
v2 = R3Vector(x=2, y=2, z=3)
print(v1.norm())
print(v2.norm())