diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..def17ea 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..fc33c94 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..db221a3 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..3ae5486 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,45 @@ -import pandas as pd -import numpy as np -import math - -"write your solution here" +import math class complex_number: - """The complex number class. + def __init__(self, real, imag=0.0): + self.real = real + self.imag = imag + + def __str__(self): + return str(self.real) + ' + i' + str(self.imag) - Attributes: - attr1 (x): Real part of complex number. - attr2 (y): Imaginary part of complex number. + ##This function adds two complex numbers. Returns result as another complex number## + def __add__(self,other): + return complex_number(self.real + other.real, + self.imag + other.imag) + + ##This function subtracts two complex numbers. Returns result as another complex number## + def __sub__(self,other): + return complex_number(self.real - other.real, + self.imag - other.imag) + + ##This function multiplies two complex numbers. Returns result as another complex number## + def __mul__(self, other): + return complex_number(self.real * other.real - self.imag * other.imag, + self.imag * other.real + self.real * other.imag) + + ##This function finds division of two complex numbers. Returns result as another complex number## + def __truediv__(self, other): + base = float(math.pow(other.real,2) + math.pow(other.imag,2)) + r = self.real * other.real + self.imag * other.imag + i = self.imag * other.real - self.real * other.imag + return (r/base, i/base) + + ##This function finds conjugate of complex number.## + def conjugate(self): + return complex_number(self.real, -self.imag) + + ##This function finds absolute of complex number.## + def abs(self): + return math.sqrt(math.pow(self.real,2) + math.pow(self.imag,2)) + + ##This function finds argument of complex number in degrees.## + def argument(self): + return math.degrees(math.atan(self.imag / self.real)) - """ diff --git a/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc b/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc index 58575f1..be60e8d 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..4aaa93d 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