Python Program To Find Factorial Of A Number

Vipin | Tue, 02 Jun, 2020 | 265

In this example, you will learn to calculate the factorial of a number entered by the user.

The factorial of a positive number n is given by:

factorial of n (n!) = 1 * 2 * 3 * 4....n

The factorial of a negative number doesn't exist. And, the factorial of 0 is 1.

Factorial of a Number

n=int(input("Enter the number : "))  # input from user

factorial = 1   # assign initial value to 1

for i in range(1,n+1):
    factorial*=i  # multiplying by i and storing back to factorial

print('Factorial of',n,"is",factorial)

Output

Enter an integer: 10
Factorial of 10 = 3628800

0 comments
Leave a comment