Home ยป Find Factorial of a Number in Python

Find Factorial of a Number in Python

In this example we will show you how to work out the factorial of a number in python

The factorial of a non negative number is the product of all the integers from 1 to that number.

For example, the factorial of 6 is 1*2*3*4*5*6 = 720 .

In this example we are using the built in math module factorial function on the number

Example

import math 

myNumber = int(input(" Please enter any Integer : "))

myFactorial = math.factorial(myNumber)
print("The Result of %d  = %d" %(myNumber, myFactorial))

When you run this you will see something like this

>>> %Run factorial.py
 Please enter any Integer : 5
The Result of 5  = 120

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More