Find Factorial of Number in Python Using Recursion
(Last Updated On: 30/11/2022)
Python Program to Find Factorial of Numbers Using Recursion
# Find Factorial of Number in Python Using Recursion
def recur_factorial(n):
if n == 1:
return n
else:
return n*recur_factorial(n-1)
# we are taking a number from user as input
# entered value will be converted to int from string
num = int(input("Enter a number: "))
# check if the number is negative
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
# number is passed to the recur_factorial() function
print("The factorial of", num, "is", recur_factorial(num))