Horje
def factorial python Code Example
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)
factorial python
def factorial(n)
    if n < 2:
        return 1
    else:
        return n * factorial(n - 1)
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




Python

Related
get next element while looping Code Example get next element while looping Code Example
While importing we detected an older version of numpy in Code Example While importing we detected an older version of numpy in Code Example
spacy import doc Code Example spacy import doc Code Example
read_json Code Example read_json Code Example
How to get ouput from python? Code Example How to get ouput from python? Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7