Factorial Calculation Function

  • Share this:

Code introduction


This function calculates the factorial of a given non-negative integer. The factorial of a number is the product of all positive integers less than the number. For example, 5! is 5*4*3*2*1=120.


Technology Stack : Recursive call

Code Type : Recursive function

Code Difficulty : Intermediate


                
                    
def factorial(n, accumulator=1):
    if n == 0:
        return accumulator
    else:
        return factorial(n-1, n*accumulator)                
              
Tags: