You can download this code by clicking the button below.
This code is now available for download.
Calculates the factorial of a non-negative integer using recursion.
Technology Stack : Recursion
Code Type : Recursive function
Code Difficulty : Intermediate
def factorial(n, accumulator=1):
if n < 0:
raise ValueError("Input must be a non-negative integer")
if n == 0:
return accumulator
else:
return factorial(n - 1, n * accumulator)