3 ms·
> def tail_factorial(n, accumulator=1): > if n == 0: return 1 > else: return tail_factorial(n-1, accumulator * n) The second line should be "if n == 0: ret
by bru 9y ago
> def tail_factorial(n, accumulator=1):
> if n == 0: return 1
> else: return tail_factorial(n-1, accumulator * n)
The second line should be "if n == 0: return accumulator"
- rahimnathwani 9y ago0! == 1 EDIT: Oops. As pointed out below, the code is indeed incorrect, and my comment is irrelevant.
- kelnage 9y agoTrue, but irrelevant. For all values of n > 1, that function will return 1, which is clearly not what the author intended.