diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-20 21:40:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-20 21:40:27 +0100 |
| commit | b521af146ef7c2bd338bc5355e2fc8f6c49cbd30 (patch) | |
| tree | 8d8e24fcdbb56212b91343e1306cce425826dc53 /challenge-072/paulo-custodio/python/ch-1.py | |
| parent | 962fb60ab30715e2dedc4fda8619042d22fba65e (diff) | |
| parent | 4ae5477a9bc6c8b01ee984ed6a5a90dbec170833 (diff) | |
| download | perlweeklychallenge-club-b521af146ef7c2bd338bc5355e2fc8f6c49cbd30.tar.gz perlweeklychallenge-club-b521af146ef7c2bd338bc5355e2fc8f6c49cbd30.tar.bz2 perlweeklychallenge-club-b521af146ef7c2bd338bc5355e2fc8f6c49cbd30.zip | |
Merge pull request #10874 from pauloscustodio/master
Add Python solution to challenge 067
Diffstat (limited to 'challenge-072/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-072/paulo-custodio/python/ch-1.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-072/paulo-custodio/python/ch-1.py b/challenge-072/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..8f455f1ac8 --- /dev/null +++ b/challenge-072/paulo-custodio/python/ch-1.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +# Challenge 072 +# +# TASK #1 > Trailing Zeroes +# Submitted by: Mohammad S Anwar +# You are given a positive integer $N (<= 10). +# +# Write a script to print number of trailing zeroes in $N!. +# +# Example 1 +# Input: $N = 10 +# Output: 2 as $N! = 3628800 has 2 trailing zeroes +# +# Example 2 +# Input: $N = 7 +# Output: 1 as $N! = 5040 has 1 trailing zero +# +# Example 3 +# Input: $N = 4 +# Output: 0 as $N! = 24 has 0 trailing zero + +import re +import sys + +def fact(n): + if n < 2: + return 1 + else: + return n*fact(n-1) + +def trailing_zeros(n): + s = str(n) + if m := re.search(r'0+$', s): + return len(m.group(0)) + else: + return 0 + +N = int(sys.argv[1]) +print(trailing_zeros(fact(N))) |
