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 __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_create_class/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_create_class/__pycache__/build.cpython-36.pyc
Binary file not shown.
39 changes: 33 additions & 6 deletions q01_create_class/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@
import numpy as np
import math

"write your solution here"


class complex_number:
"""The complex number class.
def __init__(self,real,imag):
self.real=real
self.imag=imag

def __str__(self):
return '{:d}{:+d}j'.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):
real=((self.real*other.real)-(self.imag*other.imag))
imag=((self.real*other.imag)+(self.imag*other.real))
return complex_number(real,imag)

def __truediv__(self,other):

real=((self.real*other.real)+(self.imag*other.imag))/(other.real**2+other.imag**2)
imag=((self.imag*other.real)-(self.real*other.imag))/(other.real**2+other.imag**2)
return (real,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.imag/self.real))


Attributes:
attr1 (x): Real part of complex number.
attr2 (y): Imaginary part of complex number.

"""
Binary file modified q01_create_class/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.