Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs251-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
VISHWAJEET SINGH BAGDAWAT
cs251-taskB
Commits
c4918cd0
Commit
c4918cd0
authored
Aug 27, 2016
by
Vishwajeet404
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added myexponent and changed comlexno
parent
7ec6e7fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
18 deletions
+54
-18
complexno.py
complexno.py
+30
-18
trytypes.py
trytypes.py
+24
-0
No files found.
complexno.py
View file @
c4918cd0
class
ComplexNumber
:
real
=
0.0
img
=
0.0
def
__init__
(
self
,
real
=
0
,
img
=
0
):
def
__init__
(
self
,
real
,
img
):
self
.
real
=
real
self
.
img
=
img
...
...
@@ -9,7 +9,7 @@ class ComplexNumber:
if
(
self
.
img
==
0
):
return
"
%
s"
%
(
self
.
real
)
elif
(
self
.
real
==
0
):
return
"
%
s"
%
(
self
.
img
)
return
"
i
%
s"
%
(
self
.
img
)
else
:
return
"
%
s+i
%
s"
%
(
self
.
real
,
self
.
img
)
...
...
@@ -18,9 +18,14 @@ class ComplexNumber:
def
__add__
(
self
,
other
):
sum_real
=
self
.
real
+
other
.
real
sum_img
=
self
.
real
+
other
.
real
sum_img
=
self
.
img
+
other
.
img
return
ComplexNumber
(
sum_real
,
sum_img
)
def
__sub__
(
self
,
other
):
sub_real
=
self
.
real
-
other
.
real
sub_img
=
self
.
img
-
other
.
img
return
ComplexNumber
(
sub_real
,
sub_img
)
def
__mul__
(
self
,
other
):
mul_real
=
self
.
real
*
other
.
real
-
self
.
img
*
other
.
img
mul_img
=
self
.
real
*
other
.
img
+
self
.
img
*
other
.
real
...
...
@@ -31,21 +36,28 @@ class ComplexNumber:
rmul_img
=
self
.
img
*
other
return
ComplexNumber
(
rmul_real
,
rmul_img
)
def
__sub__
(
self
,
other
):
sub_real
=
self
.
real
-
other
.
real
sub_img
=
self
.
real
-
other
.
real
return
ComplexNumber
(
sub_real
,
sub_img
)
def
__div__
(
self
,
other
):
def
__truediv__
(
self
,
other
):
div_real
=
(
self
.
real
*
other
.
real
+
self
.
img
*
other
.
img
)
/
(
other
.
real
**
2
+
other
.
img
**
2
)
div_img
=
(
self
.
img
*
other
.
real
-
self
.
real
*
other
.
img
)
/
(
other
.
real
**
2
+
other
.
img
**
2
)
return
ComplexNumber
(
div_real
,
div_img
)
def
__eq__
(
self
,
other
):
if
(
self
.
real
==
other
.
real
and
self
.
img
==
other
.
img
):
return
True
else
:
return
False
def
__pow__
(
self
,
other
):
if
other
==
0
:
return
ComplexNumber
(
1
,
0
)
else
:
if
(
other
%
2
)
==
0
:
y
=
self
**
(
other
/
2
)
z
=
y
*
y
return
z
else
:
y
=
self
**
(
other
-
1
)
z
=
self
*
y
return
z
i1
=
ComplexNumber
(
1
,
1
)
i2
=
ComplexNumber
(
2
,
0
)
i3
=
i1
+
i2
# print(sum([i1,i2]))
i4
=
i1
*
i3
print
(
i1
)
print
(
i2
)
print
(
i3
)
print
(
i4
)
\ No newline at end of file
trytypes.py
0 → 100644
View file @
c4918cd0
from
complexno
import
*
def
factorialc
(
a
):
y
=
a
b
=
ComplexNumber
(
0
,
0
)
if
y
==
b
:
return
ComplexNumber
(
1
,
0
)
else
:
c
=
ComplexNumber
(
1
,
0
)
d
=
y
-
c
return
y
*
factorialc
(
d
)
def
factorial
(
y
):
if
y
==
0
:
return
1
else
:
return
y
*
factorial
(
y
-
1
)
def
myexponent
(
x
):
if
type
(
x
)
==
type
(
ComplexNumber
(
1
,
1
)):
sum_exp
=
sum
([(
x
**
y
)
/
factorialc
(
ComplexNumber
(
y
,
0
))
for
y
in
range
(
50
)])
return
sum_exp
else
:
sum_exp
=
sum
([(
x
**
y
)
/
factorial
(
y
)
for
y
in
range
(
7
)])
return
sum_exp
\ No newline at end of file
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