Path: csiph.com!news.redatomik.org!gegeweb.org!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Vlastimil Brom Newsgroups: comp.lang.python Subject: Re: Trailing zeros of 100! Date: Sat, 2 Jan 2016 13:44:26 +0100 Lines: 38 Message-ID: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de N+zggPoyIlOLRg77ivii/QiTa6sj50ISqQrL196L/9Wg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'resulting': 0.04; 'newbie': 0.05; 'trailing': 0.07; 'zeros': 0.09; 'python': 0.10; ':-)': 0.12; '"0"': 0.16; 'failed.': 0.16; 'preserved': 0.16; 're,': 0.16; 're.search(': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'string': 0.17; 'module,': 0.18; 'input': 0.18; '>>>': 0.20; 'math': 0.20; 'to:2**1': 0.21; 'text,': 0.22; 'trying': 0.22; 'help.': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; 'regular': 0.29; 'indentation': 0.29; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.30; 'skip:s 30': 0.31; 'url:python': 0.33; 'url:listinfo': 0.34; 'received:google.com': 0.35; 'i.e.': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'version': 0.38; 'received:209': 0.38; 'thank': 0.38; 'hi,': 0.38; 'end': 0.39; 'rather': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'some': 0.40; 'more': 0.63; 'here!': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=w/VzSUYBZ9Jbh6F2EGwZwoIvmHxiHk9jyvr93Ue/Y0I=; b=lIzTjnVqxtCamUcddCHS3rE4G52LUxZidSSXzOZTm90Xb3YkQAgX0QhMfn4tYss8To 5xONMTU3K7zqVfj4Xro+yRlueuBCQTWn16EkAMDw7uyvEpbCu3uSrSix7eUMM29oDeKW stEQV/vLDxmuPBGYtGdppMqjlyXcGyquHuCpi0QKJqjTejtVruivmLwWQjeCf7E14RQm rdWw4jOOln1YnHbTXTP42TwcYD0M+hFoNjnc/6Zzd9rQxLp1VtROggP4ng/uOr5ZPRH0 N+tesdzRbbXsm56hzO16iR5mjKhOTon4QimkiVhdEXNKTjeOsjDfV7BabDPywrsXH5IK GeQA== X-Received: by 10.112.169.65 with SMTP id ac1mr10463433lbc.123.1451738666106; Sat, 02 Jan 2016 04:44:26 -0800 (PST) In-Reply-To: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101143 2016-01-02 12:49 GMT+01:00 : > 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