Welcome folks today in this post we will be finding factorial
of number using recursion
method in python. All the full source code of the application is given below.
Get Started
In order to get started you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Factorial of a number using recursion def recur_factorial(n): if n == 1: return n else: return n*recur_factorial(n-1) 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: print("The factorial of", num, "is", recur_factorial(num)) |
Now if you execute the python
script by typing the below command
python app.py