Sep-30-2018, 11:20 PM
I'm trying to understand this concept ( by the way, don't know if will ever use it but it's in this tutorial that is really basic and I would be ashame not to learn it ) through a function:
Is this correct? But then, I don't get why it contiunes with 3, 6 etc.
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)with an output:
Output:1
3
6
10
15
21
I think that I understand why output starts with 1 - because whenever execution of function comes to tri_recursion(k-1)it starts all over from the top of function until it comes to result 1.
Is this correct? But then, I don't get why it contiunes with 3, 6 etc.