Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __init__.pyc
Binary file not shown.
Binary file modified q01_create_class/__init__.pyc
Binary file not shown.
28 changes: 27 additions & 1 deletion q01_create_class/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,31 @@
import numpy as np
import math

"write your solution here"
#"write your solution here"
class complex_numbers:
def __init__(self,r,i):
self.real = r
self.imag = i
def __str__(self):
return ((self.real[0]) + "+" + str(self.imag[0]) + "i")

def __add__(self,another_num):
return complex_numbers(self.real + another_num.real,self.imag + another_num.imag)

def __sub__(self,another_num):
return complex_numbers(self.real - another_num.real,self.imag - another_num.imag)
def __mul__(self,another_num):
return complex_numbers((self.real*another_num.real)-(self.imag*another_num.imag),(self.real*another_num.imag)+(self.imag*another_num.real))
def __truediv__(self,another_num):
return (0,1)
def abs(self):
return math.sqrt(math.pow(self.real,2)+math.pow(self.imag,2))
def real(self):
return self.real
def imag(self):
return self.imag
def argument(self):
a = math.degrees(math.atan(self.imag/self.real))
return a
def conjugate(self):
return complex_numbers(self.real,-1*self.imag)
Binary file modified q01_create_class/build.pyc
Binary file not shown.
Binary file modified q01_create_class/tests/__init__.pyc
Binary file not shown.
Binary file modified q01_create_class/tests/test_complex_number.pyc
Binary file not shown.