In this article you will learn about python program to calculate the sum of a list of numbers using recursion.

Initially we take empty list, Then ask user to enter size of list i.e, int and then ask user to enter the list of items in the list one by one using for loop and append it to empty list.

Once we get the list of integers. We define find_sum() function and pass the list1 as list argument and length of the list as second argument that is index.

We traverse the list from last to zeroth element and calculate the sum by traversing using recursion.

After computing the sum we print the sum of list, using the print function.

 

Video Tutorial 

 

 

 

Below is the Python Program

# write a python program to calculate the sum of a list of numbers using recursion.



my_list = []
list_length = int(input("Enter Size of List : "))
for x in range(list_length):
list_item = int(input("Enter List Item : "))
my_list.append(list_item)


def find_sum(list1, index):
if index == 0:
return list1[index]
return list1[index] + find_sum(list1, index - 1)


print(find_sum(my_list, len(my_list) - 1))