Hi @imzyrk ,
This is an example of a recursion, which is an occurrence of a function calling itself ...
# base case
if x == 0:
# recursive case
return x * factorial(x - 1)
In a typical recursion, the problem is apportioned into two parts, namely a base case and a recursive case.
The base case is a simple case, in which the function returns a value without calling itself. For example the factorial of
n is either
1, is simply
For a factorial, if
n is higher than
1, we can get the solution by multiplying
n by the factorial of
n - 1. For instance, the factorial of
3 * 2 * 1, which is
3 multiplied by the factorial of
2. That is a recursive case.
The following demonstrates that
5 * factorial(4) is the same as
# The following should produce the same result
print 5 * factorial(4)