Computer Science, asked by ssen7450, 11 months ago

Write a recursive code to find the sum of all elements of a list

Answers

Answered by brandonsamjames
7

Answer:

Explanation:

def sum_arr(arr,size):

  if (size == 0):

    return 0

  else:

    return arr[size-1] + sum_arr(arr,size-1)

n=int(input("Enter the number of elements for list:"))

a=[]

for i in range(0,n):

   element=int(input("Enter element:"))

   a.append(element)

print("The list is:")

print(a)

print("Sum of items in list:")

b=sum_arr(a,n)

print(b)

Similar questions