Trailing zeros of 100!

Vlastimil Brom vlastimil.brom at gmail.com
Sat Jan 2 07:44:26 EST 2016


2016-01-02 12:49 GMT+01:00  <katye2007 at gmail.com>:
> Hi, newbie here!
> 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.
>
> Thank you,
> Yehuda
> --
> https://mail.python.org/mailman/listinfo/python-list

Hi,
rather an illustration of the available tools in python, than a
(submittable) solution:

>>> import re, math
>>> len(re.search(r"0*$", str(math.factorial(100))).group())
24
[or the same code on more lines with some indentation - if it is
preserved via e-mail]
>>> len(
...     re.search(
...         r"0*$",
...         str(
...             math.factorial(100)
...             )
...         ).group()
...     )
24
>>>

I.e. You need the length of the string resulting as the match of the
regular expression search for a pattern representing zero or more "0"
at the end of the input text, which is the string version of 100!

Of course, there are other ways to get this result :-)

regards,
    vbr



More information about the Python-list mailing list