Factorial of a Number in Python Using Recursion

(Last Updated On: 09/12/2022)

Python Program to Find Factorial of the Number Using Recursion

# Find Factorial of the Number in Python Using Recursion
# recursive function to calculate number factorial
def getFact(n):  
    return n if (n==1) else n * getFact(n - 1);  

num = 5

# print output
print("Factorial of",num,"is",getFact(num))

Output:

Enter any number: 5
Factorial is 120

Leave a Reply

Your email address will not be published. Required fields are marked *