Write a program to find the factorial of the given number


This program takes an input from the user in the form of an integer and assigns it to the variable 'f'. The program then initializes a variable 'fact' with a value of 1. It then checks if the input value is less than 0, in which case it prints a message saying "Factorial does not exist for Negative Values". If the input value is equal to 0, the program prints "The Factorial of 0 is 1".

If the input value is greater than 0, the program enters a for loop that runs from 1 to the input value + 1. In each iteration of the loop, the variable 'fact' is multiplied by the current value of the loop variable 'i'. Once the loop completes execution, the program prints "The Factorial [input value] is : [factorial value]". It's a program to find the factorial of number.

Source Code

f = int(input("Enter the Number :"))
fact = 1    
if(f< 0):    
   print("Factorial does not exist Negative Values")    
elif(f== 0):    
   print("The Factorial of 0 is 1")    
else:    
   for i in range(1,f + 1):    
       fact = fact*i    
   print("The Factorial",f,"is :",fact)  

Output

Enter the Number :5
The Factorial 5 is : 120

Example Programs