diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..46094ba 100644 Binary files a/__pycache__/__init__.cpython-36.pyc and b/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_create_class/__pycache__/__init__.cpython-36.pyc b/q01_create_class/__pycache__/__init__.cpython-36.pyc index 09a1efa..2595b33 100644 Binary files a/q01_create_class/__pycache__/__init__.cpython-36.pyc and b/q01_create_class/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_create_class/__pycache__/build.cpython-36.pyc b/q01_create_class/__pycache__/build.cpython-36.pyc index 9f53117..81a48c6 100644 Binary files a/q01_create_class/__pycache__/build.cpython-36.pyc and b/q01_create_class/__pycache__/build.cpython-36.pyc differ diff --git a/q01_create_class/build.py b/q01_create_class/build.py index a0188d6..c847e9d 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,73 @@ +# %load q01_create_class/build.py import pandas as pd import numpy as np import math -"write your solution here" +'write your solution here' class complex_number: - """The complex number class. + def __init__(self, real = 0, imag = 0): + self.real = real + self.imag = imag + + def __str__(self): + if self.imag<0: + return '{}-i{}'.format(self.real,abs(self.imag)) + else: + return '{}+i{}'.format(self.real,self.imag) + + def __add__(self,other): + c = self.real+other.real + d = self.imag+other.imag + return complex_number(c,d) + + def __sub__(self,other): + c= self.real-other.real + d= self.imag-other.imag + return complex_number(c,d) + + def __mul__(self,other): + c= (self.real*other.real - self.imag*other.imag) + d= (self.real*other.imag + self.imag*other.real) + return complex_number(c,d) + + def __truediv__(self,other): + c= ((self.real*other.real+self.imag*other.imag))/(other.real**2+other.imag**2) + d= ((self.imag*other.real-self.real*other.imag))/(other.real**2+other.imag**2) + #return complex_number(c,d) + return c,d + + def conjugate(self): + c = self.real + d = self.imag + return complex_number(c,-d) + + def abs(self): + c = (self.real**2+self.imag**2)**(1/2) + return c + + def argument(self): + c = math.degrees(np.arctan(self.real/self.imag)) + return c + + +aa = complex_number(3,3) +#bb = complex_number(9,9) +#print(aa) +#math.tanh +#aa.abs() +print(aa.argument()) +c1 = complex_number(4,4) +c2 = complex_number(4,-3) +print (c1) +print (c2) +print(c1+c2) +print(c1-c2) +print(c1*c2) +print(c1/c2) +print(c1.conjugate()) +print(c1.abs()) +print(c1.argument()) - Attributes: - attr1 (x): Real part of complex number. - attr2 (y): Imaginary part of complex number. - """ diff --git a/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc b/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc index 58575f1..a8f0601 100644 Binary files a/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc and b/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_create_class/tests/__pycache__/test_complex_number.cpython-36.pyc b/q01_create_class/tests/__pycache__/test_complex_number.cpython-36.pyc index b378e09..46c57cf 100644 Binary files a/q01_create_class/tests/__pycache__/test_complex_number.cpython-36.pyc and b/q01_create_class/tests/__pycache__/test_complex_number.cpython-36.pyc differ