Get factorial of any number in Python

Question

Input = 5

Output = 1*2*3*4*5 = 120

 

in progress 0
TheDataMonk 3 years 4 Answers 579 views Grand Master 0

Answers ( 4 )

  1. Input = int(input(“Enter number:”))

    factorial=1
    for i in range(1,Input+1):
    factorial=factorial*i
    factorial

  2. def factorial(n):
    if n==0 or n==1:
    return 1
    else:
    ans=1
    for i in range(1,n+1):
    ans*=i
    return ans

    if __name__==’__main__’:
    n=int(input(“Enter a number”))
    print(“the factorial of the number is”,factorial(n))

  3. def factorial(x):
    y=[]
    while x>1:
    y.append(x)
    x=x-1
    product=np.product(y)
    print(product)
    factorial(4)

    Output: 24

  4. input = 6
    fact=1
    for i in range(1,input+1):
    fact=fact*i
    print(fact)

Leave an answer

Browse
Browse