diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..e2c606e 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..31b0a5d 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..0c35be6 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..1b4841c 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,49 @@ -import pandas as pd -import numpy as np import math +import numpy as np + +class complex_number(): + + def __init__(self, real=0.0,imag=0.0): + self.real=real #real part + self.imag=imag #imaginary part -"write your solution here" + def __repr__(self): + if self.real == 0.0 and self.imag == 0.0: + return '0.00' + if self.real == 0: + return '%.2fi' % self.imag + if self.imag == 0: + return '%.2f' % self.real + return '%.2f %s %.2fi' % (self.real, '+' if self.imag >= 0 else '-', abs(self.imag)) + + def abs(self): + return (self.real**2+self.imag**2)**0.5 + + def argument(self): + return math.degrees(np.arctan(self.real/self.imag)) + + def conjugate(self): + return complex_number(self.real,-self.imag) + + def __add__(self,other): + a1=self.real+other.real + b1=self.imag+other.imag + return complex_number(a1,b1) + def __sub__(self,other): + a1=self.real-other.real + b1=self.imag-other.imag + return complex_number(a1,b1) + + def __mul__(self,other): + a1= (self.real*other.real)-(self.imag*other.imag) + b1= (self.real*other.imag)+(other.real*self.imag) + return complex_number(a1,b1) + + 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 c,d -class complex_number: - """The complex number class. - 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..007f4d6 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..16b3ff0 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