import math
num = 5
print("The factorial of 5 is : ", end="")
print(math.factorial(num))
# output - The factorial of 5 is : 120
# The factorial of a number is the function that multiplies the number by every natural number below it
# e.g. - 1 * 2 * 3 * 4 * 5 = 120
# Python 3 program to find
# factorial of given number
# Function to find factorial of given number
def factorial(n):
if n == 0:
return 1
return n * factorial(n-1)
# Driver Code
num = 5;
print("Factorial of", num, "is",
factorial(num))
# This code is contributed by Smitha Dinesh Semwal
# ___PYTHON___
# Finding factorial of a number:
userInput = int(input("Enter an integer: "))
def factorial(n):
if n == 0 or n == 1:
return 1
else :
return n * factorial(n - 1)
x = factorial(userInput)
print(x)
# Python Program to find the factors of a number
# This function computes the factor of the argument passed
def print_factors(x):
print("The factors of",x,"are:")
for i in range(1, x + 1):
if x % i == 0:
print(i)
num = 320
print_factors(num)
Python 3 program to find factorial of given number
# Python 3 program to find
# factorial of given number
def factorial(n):
# single line to find factorial
return 1 if (n==1 or n==0) else n * factorial(n - 1)
# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial(num))
# This code is contributed by Smitha Dinesh Semwal
Python 3 program to find factorial of given number
# Python 3 program to find
# factorial of given number
def factorial(n):
# single line to find factorial
return 1 if (n==1 or n==0) else n * factorial(n - 1)
# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial(num))
# This code is contributed by Smitha Dinesh Semwal
Python 3 program to find factorial of given number
# Python 3 program to find
# factorial of given number
def factorial(n):
# single line to find factorial
return 1 if (n==1 or n==0) else n * factorial(n - 1)
# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial(num))
# This code is contributed by Smitha Dinesh Semwal
#easy way to find factorial of number with while
b=1
a=int(input('the number to be entered'))
c=1
while c<=a:
b*=c
c+=1
print('factorial',a,'is',b)
#output:
the number to be entered x
factorial x is x!
+-+-+-+-+-+-+-+-+++-+-+-+-+-+-+++-+-+++-+++-+-++-+-A
# Python program to find the factorial of a number provided by the user.
# change the value for a different result
num = 7
# To 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)
Python 3 program to find factorial of given number
# Python 3 program to find
# factorial of given number
def factorial(n):
# single line to find factorial
return 1 if (n==1 or n==0) else n * factorial(n - 1)
# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial(num))
# This code is contributed by Smitha Dinesh Semwal
# Python 3 program to find
# factorial of given number
# Function to find factorial of given number
def factorial(n):
res = 1
for i in range(2, n+1):
res *= i
return res
# Driver Code
num = 5;
print("Factorial of", num, "is",
factorial(num))