diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..f6c9a04 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..742e28d 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..684f337 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..a08bc3a 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,55 @@ +# %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. + '''The complex number class. Attributes: attr1 (x): Real part of complex number. - attr2 (y): Imaginary part of complex number. + attr2 (y): Imaginary part of complex number.''' + def __init__(self,real,imag): + self.real= real + self.imag=imag + def __add__(self,another_complex): + a=self.real + another_complex.real + b=self.imag + another_complex.imag + c=complex_number(a,b) + return c +# def __repr__(self): +# return str(self.real)+ ' + ' + str(self.imag)+'i' +# return (self.real,self.imag) + def __sub__(self,another_complex): + a=self.real - another_complex.real + b=self.imag - another_complex.imag + c=complex_number(a,b) + return c + def __mul__(self,another_complex): + a=self.real * another_complex.real - self.imag*another_complex.imag + b=self.real * another_complex.imag + self.imag*another_complex.real + c=complex_number(a,b) + return c + def __truediv__(self,another_complex): + a=((self.real*another_complex.real)+(self.imag*another_complex.imag))/(another_complex.real**2 + another_complex.imag**2) + b=((self.imag*another_complex.real)-(self.real*another_complex.imag))/(another_complex.real**2 + another_complex.imag**2) + c=complex_number(a,b) + return a,b + def abs(self): + return (self.real**2 + self.imag**2)**0.5 + def argument(self): + return math.degrees(math.atan(self.imag/self.real)) + +a=complex_number(2,3) + +b=complex_number(4,5) +b +a/b +c=a+b +c.imag +a.argument() + - """ diff --git a/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc b/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc index 58575f1..ce2d32d 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..c3acfc9 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