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.
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)
Enter an integer: 10 Factorial of 10 = 3628800