Learn Special Methods by Building a Vector Space - Step 60

Tell us what’s happening:

what is it im doing wrong?? also just a general question as the reader(you) are aware chatgpt helps majorly with coding, if i use chatgpt is it considered cheating, i was thinking this because in jobs and in the real world you use chatgpt so why not use it now??

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})'

    def __add__(self, other):
        if type(self) != type(other):
            return NotImplemented
        kwargs = {i: getattr(self, i) + getattr(other, i) for i in vars(self)}
        return self.__class__(**kwargs)

    def __sub__(self, other):
        if type(self) != type(other):
            return NotImplemented
        kwargs = {i: getattr(self, i) - getattr(other, i) for i in vars(self)}
        return self.__class__(**kwargs)

    def __mul__(self, other):
        if type(other) in (int, float):
            kwargs = {i: getattr(self, i) * other for i in vars(self)}
            return self.__class__(**kwargs)        
        elif type(self) == type(other):
            args = [getattr(self, i) * getattr(other, i) for i in vars(self)]
            return sum(args)            
        return NotImplemented

# User Editable Region

    def __eq__(self, other):
        if type(self) != type(other):
            return NotImplemented
        elif getattr(self,i) == getattr(other,i):
            return True
        else:
            return False

# User 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 = R2Vector(x=0.5, y=1.25)
print(f'v1 = {v1}')
print(f'v2 = {v2}')
v3 = v1 + v2
print(f'v1 + v2 = {v3}')
v4 = v1 - v2
print(f'v1 - v2 = {v4}')
v5 = v1 * v2
print(f'v1 * v2 = {v5}')

Your browser information:

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

Challenge Information:

Learn Special Methods by Building a Vector Space - Step 60

and the error im getting is `The eq method should return True if each attribute of the current instance is equal to the same attribute of other and False otherwise.

`

Hi @Mr.Merati

I see you are onto step 61.

The concern with using a chat bot is that the learner may end up not fully understanding the fundamentals of coding, or developing critical problem solving skills, plus patience, perseverance, and self confidence.

Chat bots are based on large learning models, so the quality of the datasets can be compromised. Imagine chat bots learning from social media. What they learn to approximate can sound convincing, but may lack substance.

Job interviews sometimes require the candidate to write code on their own, explaining how a code snippet works, or the issues and challenges they faced working on a project, and how they overcame it.

Plus, instead of focusing time on learning the material, time is also spend learning to use the chat bot.

What I’ve read suggests chat bots can be used in part to test and evaluate code.

The choice is yours.

Happy coding