diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-12 10:15:37 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-12 10:15:37 +0000 |
| commit | 35b5c6a78c942743f45f11c6224a8fd4b1d0b9a1 (patch) | |
| tree | fd9cd7502bbe4a3dd3d0297cc14920f47f06fec0 /challenge-190/mohammad-anwar/python | |
| parent | e0ea162cece638e4372d52c96f5803ed70229474 (diff) | |
| download | perlweeklychallenge-club-35b5c6a78c942743f45f11c6224a8fd4b1d0b9a1.tar.gz perlweeklychallenge-club-35b5c6a78c942743f45f11c6224a8fd4b1d0b9a1.tar.bz2 perlweeklychallenge-club-35b5c6a78c942743f45f11c6224a8fd4b1d0b9a1.zip | |
- Added solutions to the task 1 of week 190.
Diffstat (limited to 'challenge-190/mohammad-anwar/python')
| -rw-r--r-- | challenge-190/mohammad-anwar/python/ch-1.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/challenge-190/mohammad-anwar/python/ch-1.py b/challenge-190/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..78d730abea --- /dev/null +++ b/challenge-190/mohammad-anwar/python/ch-1.py @@ -0,0 +1,48 @@ +#!/usr/bin/python3 + +''' + +Week 190: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-190 + +Task #1: Capital Detection + + You are given a string with alphabetic characters only: + A..Z and a..z. + + Write a script to find out if the usage of Capital is appropriate + if it satisfies at least one of the following rules: + + 1) Only first letter is capital and all others are small. + 2) Every letter is small. + 3) Every letter is capital. + +''' + +import re +import unittest + +def capitalDetection(str) -> bool: + if bool(re.search('^[A-Za-z]+$', str)): + if bool(re.search('^[A-Z][a-z]+$', str)): + return True + if bool(re.search('^[a-z]+$', str)): + return True + if bool(re.search('^[A-Z]+$', str)): + return True + + return False; + +# +# +# Unit test class + +class TestCapitalDetection(unittest.TestCase): + def test_capitalDetection(self): + self.assertTrue(capitalDetection('Perl'), 'Example 1') + self.assertTrue(capitalDetection('TPF'), 'Example 2') + self.assertFalse(capitalDetection('PyThon'), 'Example 3') + self.assertTrue(capitalDetection('raku'), 'Example 4') + +unittest.main() |
