Python Program to Find Sum of List Elements Using Recursion

Python Program to Find Sum of List Elements Using Recursion

Write Python Program to Find Sum of List Elements Using Recursion

Write Python Program to Find Sum of List Elements Using Recursion

def add_list_elements(L, n):
    result = 0
    if n == 1:
        return L[0]
    else:
        return (L[n - 1] + add_list_elements(L, n - 1))
    

L = [1, 2, 3, 4, 5]
Sum = add_list_elements(L, len(L))
print(f'Summation of Element of List {L} = {Sum}')

Output:

Summation of Element of List [1, 2, 3, 4, 5] = 15