I'm having trouble figuring out how does this exactly work. Can anyone please explain?
def fact(x):
if x == 0:
return 1
return x * fact(x - 1)
x=int(raw_input())
print fact(x)
I'm having trouble figuring out how does this exactly work. Can anyone please explain?
def fact(x):
if x == 0:
return 1
return x * fact(x - 1)
x=int(raw_input())
print fact(x)
It gets the factorial of the value x. The value of x is whatever you enter since x = int(raw_input) gets the user input. For example if x=3, then fact(3) will be 3×2=6....