Adding n1 and n2 using classes


Does anyone know how to add n1 and n2 using classes? the output should be an imaginary number.
The first arguements in n1 and n2 are real, the second arguements are imaginary. I want to add the real numbers of n1 and n2 together while also adding the imaginary numbers of n1 and n2.

add this function to Complex

def __add__(self, x):
    y = # do the calculation here
    return y
2 Likes

Then what does x do?

something like y = x.real + self.real or self.imag

3 Likes

I didn’t really want to fully give exactly how to add imaginate numbers :wink:

it’s the same thing as normal numbers iirc

1 Like

I thougth I already gave this answer but less … other stuff

1 Like

wdym? You didn’t provide any code, or tell OP how to make the __add__ method or anything

1 Like

I think that was because this might have been for a school assignment

2 Likes

But he’s in main.py, not Student.py, so I thought he is a teacher

It doesn’t seem like that when you look at their replit profile.
Also, they specifically asked how to add two class instances. It seems like they already knew the details on how exactly to mathematically add two complex numbers.

3 Likes

well normally I just give a small amount of stuff then add on it if they want more info since an info dump causes people not to read it but feeding it slowly and giving engaging convos makes it feel more fufilling

1 Like

umm

??? wth

I need the THIS emoji/reaction here

1 Like

oh nvm I thought someone else posted that code :man_facepalming:

1 Like