Home ยป Find Factorial of a Number in Python

Find Factorial of a Number in Python

Spring Framework Basics Video Course
Java SE 11 Developer (Upgrade) [1Z0-817]
Oracle Java Certification
1 Year Subscription
Java SE 11 Programmer I [1Z0-815] Practice Tests
Java SE 11 Programmer II [1Z0-816] Practice Tests

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