Python 3 Script to Find Factorial of Number Using Recursion Method Full Tutorial For Beginners

Python 3 Script to Find Factorial of Number Using Recursion Method Full Tutorial For Beginners

 

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

See also  Node.js Microsoft Azure Storage SDK Tutorial to Upload & Download Files in Browser Using Javascript Full Project For Beginners

 

app.py

 

# 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))

 

See also  Python Tkinter GUI Download Images From URL with Progressbar Full Project For Beginners

 

Now if you execute the python script by typing the below command

 

python app.py

 

 

Leave a Reply