In the Python program, we will learn how to find the factorial of a number using recursion.
Here is the source code to find the factorial of a number using recursion.
# Python Program to Find the Factorial of Number Using Recursion # Define a Function def recursion_factorial(n): if n == 1: return n else: return n*recursion_factorial(n-1) # Take the Input from the User num = int(input("Enter the 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: print("The factorial of", num, "is", recursion_factorial(num))
Enter the Number: 5
The factorial of 5 is 120