You can download this code by clicking the button below.
This code is now available for download.
This function calculates the factorial of a non-negative integer, which is the product of all positive integers up to that number. It uses recursion, with an accumulator parameter `acc` for multiplication.
Technology Stack : Recursion
Code Type : Recursive function
Code Difficulty : Intermediate
def factorial(n, acc=1):
if n <= 1:
return acc
else:
return factorial(n-1, n*acc)