Learn Special Methods by Building a Vector Space - Step 31

Tell us what’s happening:

I’m quite sure this is the correct method, I consulted some documentation and confirmed this, i also have the correct output in the terminal, still i cannot manage to achieve a good solution to this simple exercise

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 vars(self).values())**0.5

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

    def __repr__(self):
        arg_list = [f'{key}={val}' for key, val in vars(self).items()]
        args = ', '.join(arg_list)
        return f'{self.__class__.__name__}({args})'

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} \nrepr = {repr(v1)}')
print(f'v2 = {v2} \nrepr = {repr(v2)}')

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36

Challenge Information:

Learn Special Methods by Building a Vector Space - Step 31

Welcome to our community!

You have forgotten to add commas between arguments and to wrap each argument with quotes separately, including the letter f in front of the second argument in both print calls. Reread the instructions.

1 Like

Each of your print calls should have two arguments, separated by commas (i.e. you should have two separate f strings in each one).

1 Like

Thank you for the help :slight_smile:

My bad, that is indeed true that I was not separating in the right way the two arguments, I was too naive on that, thanks! I won’t forget this :slight_smile:

1 Like