I'm relentlessly but fruitlessly trying to comprehend how recursion works. I have an example from one tutorial ('Problem solving with algorithms and data structures'). Why is it, that after the recursion has happened, it again makes 5 "additional" steps with the value of the variable rising upward?
Code:
def tree(branchLen):
if branchLen >= 5:
print(branchLen, '#it is pretty understandable')
tree(branchLen-15)
print(branchLen, '#stop! Why rising (get backward)?')
tree(75)
Output:
75 #it is pretty understandable
60 #it is pretty understandable
45 #it is pretty understandable
30 #it is pretty understandable
15 #it is pretty understandable
15 #stop! Why rising (get backward)?
30 #stop! Why rising (get backward)?
45 #stop! Why rising (get backward)?
60 #stop! Why rising (get backward)?
75 #stop! Why rising (get backward)?
The question has been edited several times to provide more readability (according to remarks). There may be a bit of discrepancies between questions and answers.