Edit - I have solved this problem but if its okay, I would like the experts here to still explain this problem so that other beginners could learn. You would do a way better job explaining.
I'm trying to learn recursion and I kind of get the idea of recursion (dividing a big problem into smaller solutions and then combining them together. I have a few questions about this particular problem though. Factorial.
def fact(n):
if n==1:
return 1
else:
return n*fact(n-1)
The problem is, I don't know exactly how the calculation has been done after we reduce the n value by 1 on every recursion. For example, if n = 5, then the n value would go down by 1 every time (5,4,3,2,1). What I don't get is, what happens with those values? When are they actually multiplied up together? Can someone write the output or what's happening to the n value maybe step-by-step? I have tried to visualize this on PythonTutor, it was helpful but not very helpful.
If you guys feel as if this is a repeated question or very common, please link me to a source like (Youtube) where this is explained. Thank you very much.