diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..fac2d0c 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..c633e68 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..486eb6e 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..a11d0b0 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,37 @@ +# %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, imag): + self.real = real + self.imag = imag + def __add__(self, other): + return complex(self.real+other.real, self.imag+other.imag) + def __sub__(self, other): + return complex(self.real-other.real, self.imag-other.imag) + def __mul__(self, other): + return complex(self.real*other.real-self.imag*other.imag, self.real*other.imag+self.imag*other.real) + def __truediv__(self, no): + conj = complex(no.real, no.imag*(-1)) + num = self*conj + denom = no*conj + realQuo = num.real/denom.real + imaginaryQuo = num.imag/denom.real + return (realQuo, imaginaryQuo) + + def abs(self): + return math.sqrt(self.real**2 + self.imag**2) + + def conjugate(self): + return complex(self.real, -self.imag) + def argument(self): + return math.degrees(math.atan(self.imag/self.real)) + + - 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..bbcdfb4 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..3296ba4 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