Skip to content

Commit Live PR #40

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.
50 changes: 40 additions & 10 deletions q01_create_class/build.py
Original file line number Diff line number Diff line change
@@ -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))

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