Tuesday, July 28, 2020

Write a Program to Find the Factorial of a Number in Python.

Factorial of a Number in Python.


The 
factorial function (symbol: !) says to multiply all whole numbers from our chosen number down to 1. Examples: 5! = 5 x 4 × 3 × 2 × 1 = 120;


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


OUTPUT

Enter a number :: 5
The factorial of 5 is 120


No comments:

Post a Comment

Please do not any spam link in Comment Box