“Programme factoriel à Python” Réponses codées

Python calcule factoriel

def factorial(n):
    fact = 1
    for num in range(2, n + 1):
        fact = fact * num
    return(fact)
Obedient Ox

factorielle d'un nombre en 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)
Excited Earthworm

Trouvez la faculté d'un nombre python

#Assumes n is possitive
def factorial(n):
  return 1 if n <=1 else n*factorial(n-1)
Anxious Aardvark

python factoriel

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)
Coding boy Hasya

factorielle en 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))
visualscrapper

Programme factoriel à Python

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

Réponses similaires à “Programme factoriel à Python”

Questions similaires à “Programme factoriel à Python”

Plus de réponses similaires à “Programme factoriel à Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code