Skip to content

Commit Live PR #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
60 changes: 51 additions & 9 deletions q01_create_class/build.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
import pandas as pd
import numpy as np
import math
import numpy as np

class complex_number():

def __init__(self, real=0.0,imag=0.0):
self.real=real #real part
self.imag=imag #imaginary part

def __repr__(self):
if self.real == 0.0 and self.imag == 0.0:
return '0.00'
if self.real == 0:
return '%.2fi' % self.imag
if self.imag == 0:
return '%.2f' % self.real
return '%.2f %s %.2fi' % (self.real, '+' if self.imag >= 0 else '-', abs(self.imag))

def abs(self):
return (self.real**2+self.imag**2)**0.5

def argument(self):
return math.degrees(np.arctan(self.real/self.imag))

def conjugate(self):
return complex_number(self.real,-self.imag)

def __add__(self,other):
a1=self.real+other.real
b1=self.imag+other.imag
return complex_number(a1,b1)

def __sub__(self,other):
a1=self.real-other.real
b1=self.imag-other.imag
return complex_number(a1,b1)

def __mul__(self,other):
a1= (self.real*other.real)-(self.imag*other.imag)
b1= (self.real*other.imag)+(other.real*self.imag)
return complex_number(a1,b1)

def __truediv__(self,other):
c= ((self.real*other.real+self.imag*other.imag))/(other.real**2+other.imag**2)
d= ((self.imag*other.real-self.real*other.imag))/(other.real**2+other.imag**2)
return c,d

"write your solution here"








class complex_number:
"""The complex number class.

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.