Python Factorial Calculation

  • Share this:

Code introduction


Calculate the factorial of a given non-negative integer


Technology Stack : math, random, re, sys, time

Code Type : Function

Code Difficulty : Intermediate


                
                    
import math
import random
import re
import sys
import time

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