diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..3bb45f6 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..e9cc5ca 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..ed8d6de 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..93cec1f 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,60 @@ +# %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. - """ + ''' + def __init__(self,real,imag): + self.real=real + self.imag=imag + + def __str__(self): + return str(('%s+%si'))%(self.real,self.imag) + + #Addition of two complex numbers + def __add__(self, other): + return complex_number(self.real+other.real , self.imag+other.imag) + + + #Subtraction of two complex numbers + def __sub__(self, other): + return complex_number(self.real-other.real , self.imag-other.imag) + + + #Multiplication of two complex numbers + def __mul__(self, other): + return complex_number((self.real*other.real-self.imag*other.imag),(self.imag*other.real+self.real*other.imag)) + + + #Division of two complex numbers + def __truediv__(self, other): + return ((self.real*other.real + self.imag*other.imag)/(other.real*other.real + other.imag*other.imag), + (self.imag*other.real - self.imag*other.imag)/(other.real*other.real + other.imag*other.imag)) + + + #Absolute of two numbers + def abs(self): + return math.sqrt(self.real**2 + self.imag**2) + + #Conjugate of complex number + def conjugate(self): + return (-self.real,-self.imag) + + #Arg of Complex number + def argument(self): + return math.degrees(math.atan(self.real/self.imag)) +a=complex_number(4,4) +b=complex_number(4,-3) +c=a/b +print(c) + diff --git a/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc b/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc index 58575f1..ecb24af 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..d885abf 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