Hi Perfringo,
I used Thonny. I understand what it is doing. Still I want to learn how to save the old result and print it.
n is 4 and old result is 6 the current result is 24
n is 5 and old result is 24 the current result is 120
how do I bring this 6 value into the print statement.
Thanks
I used Thonny. I understand what it is doing. Still I want to learn how to save the old result and print it.
[python]def _factorial_sample_(n): previous=0 if n == 0 or n ==1: return 1 else: result = n * _factorial_sample_(n-1) previous = result print (previous) print("n is ",n, "result",previous) return result print(_factorial_sample_(5))[/python]
Output:2
n is 2 result 2
6
n is 3 result 6
24
n is 4 result 24
120
I want to printn is 4 and old result is 6 the current result is 24
n is 5 and old result is 24 the current result is 120
how do I bring this 6 value into the print statement.
Thanks