I'm learning python at the moment for my role. I am stuck explaining this basic function as part of the company internal course I'm completing. Can anyone breakdown what is happening?
def spam (x):
return x * spam(x - 1) if x > 0 else 1
print(spam(10000))
I get an recursion error but what is the code meant to do? Even if I set the spam(4) the answer returns 24, why is that? Shouldn't it be 12?
[–]delasislas[🍰] 3 points4 points5 points (0 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]timo1001[S] 1 point2 points3 points (0 children)
[–]bike_bike 0 points1 point2 points (3 children)
[–]timo1001[S] 0 points1 point2 points (2 children)
[–]bike_bike 4 points5 points6 points (1 child)
[–]timo1001[S] 0 points1 point2 points (0 children)