COMPUTER SCIENCE PYTHON AND C++
Monday, June 29, 2020
Write a Python program to calculate the sum of a list of numbers using Recursion
def
list_sum
(
num_List
)
:
if
len
(
num_List
)
==
1
:
return
num_List
[
0
]
else
:
return
num_List
[
0
]
+
list_sum
(
num_List
[
1
:
]
)
print
(
list_sum
(
[
2
,
4
,
5
,
6
,
7
]
)
)
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment