diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2024-03-04 16:39:31 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2024-03-04 16:39:31 +0800 |
| commit | 8edd4508d3af07ed272eec6ceeca1a9789b5e68a (patch) | |
| tree | 2db742aea75a7a3005575c04a7e44da6d5c88a1f /challenge-258/pokgopun/python/ch-1.py | |
| parent | d64db60d9dcf17d59060a03f5b1fbc5e82fc1953 (diff) | |
| parent | ad381c1123e47114d3d98f1749f9f354eebafcdd (diff) | |
| download | perlweeklychallenge-club-8edd4508d3af07ed272eec6ceeca1a9789b5e68a.tar.gz perlweeklychallenge-club-8edd4508d3af07ed272eec6ceeca1a9789b5e68a.tar.bz2 perlweeklychallenge-club-8edd4508d3af07ed272eec6ceeca1a9789b5e68a.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-258/pokgopun/python/ch-1.py')
| -rw-r--r-- | challenge-258/pokgopun/python/ch-1.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-258/pokgopun/python/ch-1.py b/challenge-258/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..8232fe40f8 --- /dev/null +++ b/challenge-258/pokgopun/python/ch-1.py @@ -0,0 +1,51 @@ +### https://theweeklychallenge.org/blog/perl-weekly-challenge-258/ +""" + +Task 1: Count Even Digits Number + +Submitted by: [42]Mohammad Sajid Anwar + __________________________________________________________________ + + You are given a array of positive integers, @ints. + + Write a script to find out how many integers have even number of + digits. + +Example 1 + +Input: @ints = (10, 1, 111, 24, 1000) +Output: 3 + +There are 3 integers having even digits i.e. 10, 24 and 1000. + +Example 2 + +Input: @ints = (111, 1, 11111) +Output: 0 + +Example 3 + +Input: @ints = (2, 8, 1024, 256) +Output: 1 + +Task 2: Sum of Values +""" +### solution by pokgopun@gmail.com + +def CEDN(ints: tuple): + return sum( + len(str(e)) % 2 == 0 for e in ints + ) + +import unittest + +class TestCEDN(unittest.TestCase): + def test(self): + for inpt, otpt in { + (10, 1, 111, 24, 1000): 3, + (111, 1, 11111): 0, + (2, 8, 1024, 256): 1, + }.items(): + self.assertEqual(CEDN(inpt),otpt) + +unittest.main() |
