Programming Examples

Python program to create recursive function to find factorial


Write a Python function to calculate the factorial value of given number using recursion.

Solution

def fact(n):
    if n==1:
        return 1
    else:
        return n*fact(n-1)
num=int(input("Enter any Number "))
ans=fact(num)
print("Factorial is : ",ans);
▶ RUN

Output/ Explanation:

Enter any Number 5

Factorial is :  120

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad