# Factoriale
# 0! = 1 (da! este adevarat)
# 1! = 1
# 2! = 1 * 2
# 3! = 1 * 2 * 3
# 4! = 1 * 2 * 3 * 4
# :
# :
# n! = 1 * 2 ** 3 * 4 * ... * n-1 * n
def function(param):
if param < 0:
return None
if param < 2:
return 1
var = 1 # variabila declarata in interiorul functiei
for i in range(2, param + 1):
var *= i
return var # definitia functiei se termina aici
for param in range(1, 6): # test
print(param, function(param))
# rezultat: 1 1
# 2 2
# 3 6
# 4 24
# 5 120