Hi,

Please help me understand this better, I’m having a hard time understanding the output from this portion of the code:

result = k+tri_recursion(k-1)

*Is this portion of the code saying K plus the function tri_recursion(K subtract 1 from K)?*

The function is below and the output - this example came from w3schools.com I hope it okay to reference other learning materials.

Here’s the code:

def tri_recursion(k):

if(k>0):

result = k+tri_recursion(k-1)

print(result)

else:

result = 0

return result

print("\n\nRecursion Example Results")

tri_recursion(6)

Code Output:

C:\Users\My Name>python demo_recursion.py

Recursion Example Results

1

3

6

10

15

21

*Please help.*