DEV Community

saurabh belote
saurabh belote

Posted on

recursion sum of array

arr = [90,2,3,4,5,6,7,8,9,101]
n = len(arr)
i = 0
Num = 0
def recursor(n,i,Num):
    if n == 0:
        return n
    else:
        #print(arr[i])
        Num = arr[i] + Num
        print(Num)
        i += 1
        return recursor(n-1,i,Num)

(recursor(n,i,Num))

Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
naveennamani profile image
naveennamani

Don't use sum as the variable, it's a built-in function of python

Collapse
 
s_belote_dev profile image
saurabh belote • Edited

Thanks I will not use in future