What am I doing wrong? If I add ‘*’ as second argument after self I will get an error and if I use the method I use here there will not error but I am passing the test.
Your code so far
# User Editable Region
class R2Vector:
def __init__(self, **kwargs):
self.x = kwargs.get('x')
self.y = kwargs.get('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, **kwargs):
super().__init__(**kwargs)
self.z = kwargs.get('z')
v1 = R2Vector(x=2, y=2)
print(v1.norm())
print(v1)
v2 = R3Vector(x=2, y=2, z=3)
# 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/127.0.0.0 Safari/537.36
Challenge Information:
Learn Special Methods by Building a Vector Space - Step 17
Please, read again the instructions. You are going in a different direction from what has been asked. If you have def __init__(self, x, y): and you need to add a * as the second parameter, you don’t want to change the other parameters.
To enforce keyword arguments you should have something like def foo(a, b, *, c, d ):. Then when you call the function, c and d must be keyword arguments.
In Python, you can enforce the use of keyword-only arguments by adding a * as an additional argument to the function or method signature.
Modify both __init__ methods by adding a * as the second parameter (after self). Every parameter placed after that will require the use of a keyword argument in the function/method call. ✗
For part 1 add the * as a second argument. Do not alter the rest of the expression.
This means that you need to modify the super().__init__(x, y) call, too. Do it by giving x the value x, and y the value y. ✗
Finally, modify the instantiation of v1 and v2 by using keyword arguments. ✓
You correctly modified the instantiation of v1 and v2.