I tried creating a Complex number class. I have an add method in the class which returns a new complex number after adding, without changing the argument complex numbers.
code
class complex:
real = 0.00
imag = 0.00
def __init__ (self,r,i):
complex.real = r
complex.imag = i
def add(comp1, comp2):
x = comp1.real + comp2.real
y = comp1.imag + comp2.imag
result = complex(x,y)
return result
Something is wrong with this code. I cannot find it. Please tell me where I went wrong.
I also tried passing self object but it didin't work. def add(self, comp):