Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

find the factorial of a given integer in python

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
Comment

Program for factorial of a number in python

# 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
Comment

find factorial in python

factorial = lambda n: n * factorial(n-1) if n > 1 else 1

print(factorial(3)) # 6 
print(factorial(5)) # 120
Comment

Finding factorial of a number in Python

# ___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)
Comment

Python function to compute factorial of a number.

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))
Comment

factorial of a number in python

num = int(input("Enter a number to find factorial: "))
mul = 1
for x in range(1, num+1):
    mul *= x

print("Factorial of", num, "=", mul)
Comment

factorial program in python

def Fact(num):
    z=1
    while(1):
        z=z*num
        num=num-1
        if(num==0):
            break
    
    print(z)
Fact(4)
    
Comment

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
Comment

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
Comment

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
Comment

find factorial of a number in python

# 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)
Comment

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
Comment

PREVIOUS NEXT
Code Example
Python :: python rgb to hex 
Python :: exclude last value of an array python 
Python :: index of a string index dataframe 
Python :: spotipy currently playing 
Python :: how to label points in scatter plot in python 
Python :: display array of odd rows and even columns in numpy 
Python :: keyboardinterrupt python 
Python :: legend font size python matplotlib 
Python :: pandas save dataframe to csv in python 
Python :: flask cookies 
Python :: calculate mean median mode in python 
Python :: UTC to ISO 8601 with TimeZone information (Python 3): 
Python :: how to concat on the basis of particular columns in pandas 
Python :: join dataframe pandas by column 
Python :: python dequeu 
Python :: random int python 
Python :: roman to integer 
Python :: python tkinter projects 
Python :: np.arange and np.linspace difference 
Python :: pandas cumulative mean 
Python :: soap 1.2 request python 
Python :: subtract number from each element in list python 
Python :: make an android app with python 
Python :: open csv from url python 
Python :: print python float precision 
Python :: print inline output in python 
Python :: regex remove all html tags except br python 
Python :: python see if a number is greater than other 
Python :: dataframe to tf data 
Python :: how to prepare independent and dependent variables from dataframe 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =