On 2016-01-02 03:49, [email protected] wrote:
> I'm trying to write a python program to find how many trailing
> zeros are in 100! (factorial of 100). I used factorial from the
> math module, but my efforts to continue failed. Please help.
Pretty easy to do with strings:
from math import factorial
n = factorial(100)
s = str(n)
print(len(s) - len(s.rstrip('0')))
or count them:
from itertools import takewhile
sum(1 for _ in takewhile(lambda c: c == '0', reversed(s)))
or mathematically:
sum(1 for _ in itertools.takewhile(
lambda x: n % (10**x) == 0,
itertools.count(1)))
-tkc
--
https://mail.python.org/mailman/listinfo/python-list