Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

factorial python

def factorial_iter(n):
    product = 1
    for i in range(n):
        product = product * (i+1)
    return product

def factorial_recursive(n):
    if n == 1 or n == 0:
        return 1
    return n * factorial_recursive(n-1)

# f = factorial_iter(5)
f = factorial_recursive(0)
print(f)
Comment

factorial in python

def fact(n):
	if n==0 or n==1:
		return 1
	else:
		return n*fact(n-1)
print(fact(4)) #4 is the sample value it will returns 4!==> 4*3*2*1 =24
#OR
import math
print(math.factorial(4))
Comment

factorial in python

def fact(n):
  return 1 if (n==0 or n==1) else n*fact(n-1)
fact(3)
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

python factorial

import math

math.factorial(5) # Using math module

def factorial(n): # Doing it yourself
    x = 1

    for i in range(2,n+1):
        x *= i
        
    return x
Comment

python factorial

def factorial(n):
    fact = 1
    for num in range(2, n + 1):
        fact *= num
    return fact
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 python

def factorial(n)
    if n < 2:
        return 1
    else:
        return n * factorial(n - 1)
Comment

def factorial python

def factorial(n):            # Define a function and passing a parameter
        fact = 1                 # Declare a variable fact and set the initial value=1 
        for i in range(1,n+1,1): # Using loop for iteration
            fact = fact*i            
        print(fact)              # Print the value of fact(You can also use "return")

factorial(n) // Calling the function and passing the parameter
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

program python factorial

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

factorial ofa number in python

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

PREVIOUS NEXT
Code Example
Python :: python input function 
Python :: how to download nltk in python 
Python :: replace all missing value with mean pandas 
Python :: how to sum only the even values in python 
Python :: filter function in pandas stack overflow 
Python :: replace df with 
Python :: procfile heroku python example 
Python :: Get game status discord.py 
Python :: clean punctuation from string python 
Python :: randomly choose between two numbers python 
Python :: width and height of pil image 
Python :: get first row sqlalchemy 
Python :: python list to string 
Python :: integer colomn to datetime pandas python 
Python :: int to string python 
Python :: how to add a number to each element in an array python with loop 
Python :: manipulate ip address in python 
Python :: import csv from google drive python 
Python :: The Python path in your debug configuration is invalid. 
Python :: python datetime module 
Python :: multinomial regression scikit learn 
Python :: Python function to calculate LCM of 2 numbers. 
Python :: pandas front fill 
Python :: python do nothing 
Python :: length of pandas dataframe 
Python :: as type in pandas 
Python :: decision tree regressor 
Python :: list to string 
Python :: python open and read file with 
Python :: numpy arrauy to df 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =