diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index a600305..8df4e9c 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..801f5e9 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..583f394 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..6c8d41f 100644 --- a/q01_create_class/build.py +++ b/q01_create_class/build.py @@ -1,15 +1,48 @@ +# %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): + if self.imag <0: + return '{0} +i{1}.format(self.real, self.imag)' + else: + return '{}+ i{}.format(self.real, self.imag)' + def __add__(self,other): + return complex_number(self.real + other.real, + self.imag + other.imag) + def __sub__(self,other): + return complex_number(self.real - other.real, + self.imag - other.imag) + def __mul__(self,other): + return complex_number(self.real * other.real - self.imag * other.imag, + self.imag * other.real + self.real * other.imag) + def __truediv__(first,second): + #r=(other.real+other.imag) + return((first.real * second.real+first.imag * second.imag)/(second.real*second.real +second.imag*second.imag), + (first.imag * second.real-first.imag * second.imag)/(second.real*second.real +second.imag*second.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)) + + + + + diff --git a/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc b/q01_create_class/tests/__pycache__/__init__.cpython-36.pyc index 58575f1..6e661cc 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..7710bac 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