Non-negative Integer Factorial Calculator

  • Share this:

Code introduction


Calculates the factorial of a non-negative integer


Technology Stack : Built-in functions

Code Type : Mathematical calculation

Code Difficulty : Intermediate


                
                    
def factorial(n, accumulator=1):
    if n < 0:
        return "Input must be a non-negative integer"
    elif n == 0:
        return accumulator
    else:
        return factorial(n - 1, n * accumulator)