63 Program for recursive factorial of a number in Python

Program:

#factorial program using recursive function

def fact(n):

    if(n==1):

        return 1

    else:

        return(n*fact(n-1))  #recursive function call

              
num=int(input("enter a number:"))

if(num >= 1):

    print("Factorial of",num,"is",fact(num))



''' 5*fact(4)

5*4*fact(3)

5*4*3*fact(2)

5*4*3*2*fact(1)

5*4*3*2*1=120 '''


Output:

Program for recursive factorial of a number in Python

Previous
Next Post »