Python 3 Script to Find Factorial of a Number Full Tutorial For Beginners

You are currently viewing Python 3 Script to Find Factorial of a Number Full Tutorial For Beginners

 

Welcome folks today in this tutorial we will be finding factorial of a number 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

 

 

num= int(input("Enter a number: "))

factorial = 1

# check if the number is negative, positive or zero
if num < 0:
   print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
   print("The factorial of 0 is 1")
else:
   for i in range(1,num + 1):
       factorial = factorial*i
   print("The factorial of",num,"is",factorial)

 

 

Now if you execute the python script app.py by typing the below command

 

python app.py

 

 

 

As you can see we have taken input from user and 4 factorial is 24

Leave a Reply