import
math
class
Node:
def
__init__(
self
, data):
self
.data
=
data
self
.
next
=
None
def
sumProduct(head, key):
current
=
head
sum
=
0
product
=
1
if
(head
=
=
None
):
print
(
"\nDisplay List is empty\n"
)
return
else
:
if
((current.data)
%
key
=
=
0
) :
sum
=
sum
+
current.data
product
=
product
*
current.data
current
=
current.
next
while
(current !
=
head):
if
((current.data)
%
key
=
=
0
) :
sum
=
sum
+
current.data
product
=
product
*
current.data
current
=
current.
next
print
(
"\nSum ="
,
sum
, end
=
", "
)
print
(
"Product ="
, product)
def
displayList(head):
current
=
head
if
(head
=
=
None
):
print
(
"\nDisplay List is empty\n"
)
return
else
:
print
(current.data, end
=
" "
)
current
=
current.
next
while
(current !
=
head):
print
(current.data, end
=
" "
)
current
=
current.
next
def
InsertNode(head, data):
current
=
head
newNode
=
Node(data)
if
(newNode
=
=
None
):
print
(
"\nMemory Error\n"
)
return
head
newNode.data
=
data
if
(head
=
=
None
):
newNode.
next
=
newNode
head
=
newNode
return
head
else
:
while
(current.
next
!
=
head):
current
=
current.
next
newNode.
next
=
head
current.
next
=
newNode
return
head
if
__name__
=
=
'__main__'
:
head
=
None
head
=
InsertNode(head,
5
)
head
=
InsertNode(head,
6
)
head
=
InsertNode(head,
7
)
head
=
InsertNode(head,
8
)
head
=
InsertNode(head,
9
)
head
=
InsertNode(head,
10
)
head
=
InsertNode(head,
11
)
head
=
InsertNode(head,
11
)
print
(
"Initial List: "
, end
=
"")
displayList(head)
sumProduct(head,
11
)