Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

python factor number

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

PREVIOUS NEXT
Code Example
Python :: how to merge two column pandas 
Python :: fast input python 
Python :: python tuple and dictionary 
Python :: adam optimizer keras learning rate degrade 
Python :: pandas resample friday 
Python :: wap in python to check a number is odd or even 
Python :: python dict access 
Python :: python find first occurrence in list 
Python :: trim string to max length python 
Python :: Converting Categorical variables in to integers using Dummy 
Python :: check if string match regex python 
Python :: flask No application found. Either work inside a view function or push an application context 
Python :: beautifulsoup get img alt 
Python :: obtain files python 
Python :: else if python 
Python :: python sys 
Python :: python not equal to symbol 
Python :: python namedtuples 
Python :: Python Split list into chunks using for loop 
Python :: python str of list 
Python :: python string encode 
Python :: find index of element in array python 
Python :: quantile-quantile plot python 
Python :: python return to top of loop 
Python :: check null all column pyspark 
Python :: python keyboard input 
Python :: Sum of Product 1 
Python :: save and load model during training pytorch 
Python :: check if a file exists in python 
Python :: How do I plot a csv file in Jupyter notebook? 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =