Calculating Factorials in Python

  • Share this:

Code introduction


Calculate the factorial of a given non-negative integer


Technology Stack : math, random

Code Type : Recursive function

Code Difficulty : Intermediate


                
                    
import math
import random

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