title: How does a Python recursive function works for tri_recursion function?
body: <p>I'm new to Python, I found <a href="https://www.w3schools.com/python/showpython.asp?filename=demo_recursion" rel="nofollow noreferrer">the below recursive program</a> being tough to follow. While debugging the program I could find that it goes through recursion and the value of <code>k</code> decrements -1 every time we recurse. At one point <code>k</code> is -1 and the compiler moves to the <code>else</code> part and returns 0.</p>
  <p>Finally, the <code>k</code> value turns out to be 1, how does this happen?</p>
  <pre><code>def tri_recursion(k):
    if(k&gt;0):
      result = k+tri_recursion(k-1)
      print(result)
    else:
      result = 0
    return result
  
  print(&quot;\n\nRecursion Example Results&quot;)
  tri_recursion(6)
  </code></pre>
  <p>And the output:</p>
  <pre><code>Recursion Example Results  
  1  
  3  
  6  
  10  
  15  
  21  
  </code></pre>