Hawkings
0
Q:

python factorial

# Python code to demonstrate math.factorial() 
import math 
  
print ("The factorial of 23 is : ", end="") 
print (math.factorial(23)) 
13
def factorial(n):
    fact = 1
    for num in range(2, n + 1):
        fact = fact * num
    return(fact)
1
def fact(n):
  return 1 if (n==0 or n==1) else n*fact(n-1)
fact(3)
0
# Python code to demonstrate the working of factorial() 
  
# importing "math" for mathematical operations  
import math  
  
x = 5
y = 15
z = 8
  
# returning the factorial 
print ("The factorial of 5 is : ", math.factorial(x)) 
print ("The factorial of 15 is : ", math.factorial(y)) 
print ("The factorial of 8 is : ", math.factorial(z)) 
0
def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)
n=int(input("Input a number to compute the factiorial : "))
print(factorial(n))

0

New to Communities?

Join the community