+ 1
I need help for my coding exercice
In this programm i has to calculate n! Where n is a variable of type int. Can someone help me please? n=... Factorial=... For i in range(...): ....... Print(...)
3 odpowiedzi
+ 3
iterative:
n = int(input("n: \n"))
fac = 1
for i in range(2, n):
    fac *= i
print(str(n) + "! = " + str(fac))
recusive:
def fac(n):
    if n == 0:
        return 1
    else:
        return n * fac(n-1)
n = int(input("n: \n"))
print(str(n) + "! = " + str(fac(n)))
0
Thank you so much !



