Day 38 of 100 Days of Python
Practising Recursion
1
2
3
4
5
6
7
8
9
# Sum of Array Elements
def sum_array(arr):
if len(arr)==0:
return 0
return arr[0] + sum_array(arr[1:])
ar = [5,6,7,8]
print(sum_array(ar))
This post is licensed under CC BY 4.0 by the author.