diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..6f0992e 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..73bec7f 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..04318a8 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..98aad23 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,58 @@ +# %load q01_create_class/build.py import pandas as pd import numpy as np import math +from math import pow -"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 =0.0): + self.real = real + self.imag = imag + def __str__(self): + if self.imag<0: + return '{0}-{1}i'.format(self.real,self.imag) + else: + return '{0}+{1}i'.format(self.real,self.imag) + + + + def __add__(self, num): + return complex_number(self.real + num.real, self.imag + num.imag) + def __sub__(self, num): + return complex_number(self.real - num.real, self.imag - num.imag) + + def __mul__(self, num): + return complex_number(self.real * num.real - self.imag * num.imag , self.imag * num.imag + self.real * num.real) + + def __truediv__(self, num): + return ((self.real * num.real + self.imag * num.imag)/(num.real * num.real + num.imag*num.imag), + (self.imag * num.real - self.imag * num.imag)/(num.real * num.real + num.imag * num.imag)) + def abs(self): + return math.sqrt(self.real**2 + self.imag**2) + def conjugate(self): + return complex_number(self.real , -self.imag) + def argument(self): + return math.degrees(math.atan(self.real/self.imag)) + + +a = complex_number(4,4) +b = complex_number(4,-3) + +c = complex_number(4,4) +d = complex_number(4,-3) + + + + + + diff --git a/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc b/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc index 58575f1..7655b6e 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..0c82424 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