DEV Community

saurabh belote
saurabh belote

Posted on

1

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

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay