Hacker News new | ask | show | jobs
by bru 3019 days 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"

1 comments

0! == 1

EDIT: Oops. As pointed out below, the code is indeed incorrect, and my comment is irrelevant.

True, but irrelevant. For all values of n > 1, that function will return 1, which is clearly not what the author intended.