Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BITTU KUMAR
taskB
Commits
e803c84b
Commit
e803c84b
authored
Aug 28, 2016
by
BITTU KUMAR
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
0 deletions
+119
-0
complexno.py
complexno.py
+110
-0
trytypes.py
trytypes.py
+9
-0
No files found.
complexno.py
0 → 100644
View file @
e803c84b
class
ComplexNumber
:
def
__init__
(
comp
,
x
=
0
,
y
=
0
):
comp
.
x
=
x
comp
.
y
=
y
def
__str__
(
comp
):
if
comp
.
y
<
0
:
return
"({0}-i{1})"
.
format
(
comp
.
x
,
abs
(
comp
.
y
))
else
:
return
"({0}+i{1})"
.
format
(
comp
.
x
,
comp
.
y
)
def
__add__
(
comp
,
other
):
if
(
type
(
other
)
is
ComplexNumber
):
return
ComplexNumber
(
comp
.
x
+
other
.
x
,
comp
.
y
+
other
.
y
)
else
:
return
ComplexNumber
(
comp
.
x
+
other
,
comp
.
y
)
def
__radd__
(
comp
,
other
):
if
(
type
(
other
)
is
ComplexNumber
):
return
ComplexNumber
(
comp
.
x
+
other
.
x
,
comp
.
y
+
other
.
y
)
else
:
return
ComplexNumber
(
comp
.
x
+
other
,
comp
.
y
)
def
__lt__
(
comp
,
other
):
print
(
"Not Allowed"
)
def
__gt__
(
comp
,
other
):
print
(
"Not Allowed"
)
def
__eq__
(
comp
,
other
):
return
(
comp
.
x
==
other
.
x
and
comp
.
y
==
other
.
y
)
def
__ne__
(
comp
,
other
):
return
(
comp
.
x
!=
other
.
x
or
comp
.
y
!=
other
.
y
)
def
__sub__
(
comp
,
other
):
if
(
type
(
other
)
is
ComplexNumber
)
:
x
=
comp
.
x
-
other
.
x
y
=
comp
.
y
-
other
.
y
return
ComplexNumber
(
x
,
y
)
else
:
return
ComplexNumber
(
comp
.
x
-
other
,
comp
.
y
)
def
__rsub__
(
comp
,
other
):
temp
=
ComplexNumber
(
other
,
0
)
x
=
temp
.
x
-
comp
.
x
y
=
temp
.
y
-
comp
.
y
return
ComplexNumber
(
x
,
y
)
def
__mul__
(
comp
,
other
):
if
(
type
(
other
)
is
ComplexNumber
):
x
=
comp
.
x
*
other
.
x
-
comp
.
y
*
other
.
y
y
=
comp
.
x
*
other
.
y
+
comp
.
y
*
other
.
x
return
ComplexNumber
(
x
,
y
)
else
:
return
ComplexNumber
(
other
*
comp
.
x
,
other
*
comp
.
y
)
def
__rmul__
(
comp
,
other
):
if
(
type
(
other
)
is
ComplexNumber
):
x
=
comp
.
x
*
other
.
x
-
comp
.
y
*
other
.
y
y
=
comp
.
x
*
other
.
y
+
comp
.
y
*
other
.
x
return
ComplexNumber
(
x
,
y
)
else
:
return
ComplexNumber
(
other
*
comp
.
x
,
other
*
comp
.
y
)
def
__truediv__
(
comp
,
other
):
if
(
type
(
other
)
is
ComplexNumber
):
temp
=
comp
*
conj
(
other
)
temp
=
temp
/
(
other
.
x
**
2
+
other
.
y
**
2
)
return
temp
else
:
return
ComplexNumber
(
comp
.
x
/
other
,
comp
.
y
/
other
)
def
__rtruediv__
(
comp
,
other
):
temp1
=
ComplexNumber
(
other
,
0
)
temp
=
temp1
*
conj
(
comp
)
temp
=
temp
/
(
comp
.
x
**
2
+
comp
.
y
**
2
)
return
temp
def
__pow__
(
comp
,
num
):
x
=
ComplexNumber
(
1
,
0
)
for
i
in
range
(
0
,
num
):
x
=
x
*
comp
return
x
;
def
conj
(
comp
):
if
(
type
(
comp
)
is
ComplexNumber
):
x
=
comp
.
x
y
=-
comp
.
y
return
ComplexNumber
(
x
,
y
)
else
:
return
comp
def
mag
(
comp
):
return
(
comp
.
x
**
2
+
comp
.
y
**
2
)
**
(
0.5
)
trytypes.py
0 → 100644
View file @
e803c84b
from
complexno
import
ComplexNumber
def
myexponent
(
x
):
epowx
=
1
m
=
1
for
i
in
range
(
1
,
100
):
m
*=
x
/
i
epowx
+=
m
return
epowx
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment