Learn Special Methods by Building a Vector Space - Step 26

Tell us what’s happening:

feeling challenged in this step… I’m getting the correct output, but apparently input in not right. Help please

Your code so far


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

    def norm(self):
        return sum(val**2 for val in self.__dict__.values())**0.5

    def __str__(self):
        return str(tuple(getattr(self, i) for i in vars(self)))

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

# User Editable Region

v1 = R2Vector(x=2, y=3)
v2 = R3Vector(x=2, y=2, z=3)
print(f'v1 = {v1.__str__()}')
print(f'v1 = {str(v1)}') # this also produces a correct output
print(v2.norm())

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Special Methods by Building a Vector Space - Step 26

remove this one please

also add the print for v2

thanks I figured it out… however I don’t recall there being instructions that explain that ‘f-strings’ automatically handle ‘str’ methods… perhaps I am wrong, but it certainly didn’t stick to my brain.

when you write

a = 4
str = f'The number is {a}'

you are not using explicitly the str method but it makes 4 into a string, it’s the same here with vectors