Monday, 25 January 2016

Program To Print Factorial Of Any Number

Hello friends,
Today I came with a basic program to find factorial of any number.
Factorial means multiplying all the numbers upto a particular number.
For example:-
5!=5*4*3*2*1=120
So, Just check out

# Python program to find the factorial of a number provided by the user.
def factorial():
    # take input from the user
    num = int(input("Enter a number: "))
    factorial = 1

    # check if the number is negative, positive or zero
    if num < 0:
       print("Sorry, factorial does not exist for negative numbers")
    elif num == 0:
       print("The factorial of 0 is 1")
    else:
       for i in range(1,num + 1):
           factorial = factorial*i
       print("The factorial of",num,"is",factorial)
times=input("Enter how many number you enter:-")
for i in range(times):
    factorial()

You can use it find factor very large number. 

Thanks for seeing this blog, if you like please share this blog.

No comments:

Post a Comment