Trailing zeros of 100!
Mark Lawrence
breamoreboy at yahoo.co.uk
Sat Jan 2 10:30:09 EST 2016
On 02/01/2016 13:14, yehudak . wrote:
> Vlastimil,
> Thank you so much, but...
> All that is Chinese for me.
> Can you show a 'normal' Python code for me?
>
> Yehuda
>
> On Sat, Jan 2, 2016 at 2:44 PM, Vlastimil Brom <vlastimil.brom at gmail.com>
> wrote:
>
>> 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
>>
I'll explain it if you stop top posting.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list