Code Library


Factorial number :
   
A factorial is a function that multiplies a number by every number below it till 1. For example, the factorial of 3 represents the multiplication of numbers 3, 2, 1, i.e. 3! = 3 × 2 × 1 and is equal to 6. factorial of 6 is 6*5*4*3*2*1 which is 720.

number = int(input("Enter a number: "))
factorial = 1 
if number < 0:
    print("Factorial does not exist for negative numbers")
elif number == 0:
    print("Factorial of 0 is 1")
else:
    for i in range(1, number + 1):
        factorial = factorial * i
    print("Factorial of", number, "is", factorial)
Enter a number: 4
Factorial of 4 is 24