diff options
| author | Santiago Leyva <99155189+DevSanti12@users.noreply.github.com> | 2024-07-25 23:57:49 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-25 23:57:49 -0500 |
| commit | db40d75f603f3fae34944cb3a762b290b18577d8 (patch) | |
| tree | 1205c733ae416bcbce12e225a5252841316c5540 /challenge-279/roger-bell-west/python | |
| parent | 350f495b09a4b6b6db8506533e2dccc68d9fc3f4 (diff) | |
| parent | 3d6cbce024396f3950dad9b40151458e4134202d (diff) | |
| download | perlweeklychallenge-club-db40d75f603f3fae34944cb3a762b290b18577d8.tar.gz perlweeklychallenge-club-db40d75f603f3fae34944cb3a762b290b18577d8.tar.bz2 perlweeklychallenge-club-db40d75f603f3fae34944cb3a762b290b18577d8.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-279/roger-bell-west/python')
| -rwxr-xr-x | challenge-279/roger-bell-west/python/ch-1.py | 22 | ||||
| -rwxr-xr-x | challenge-279/roger-bell-west/python/ch-2.py | 24 |
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-279/roger-bell-west/python/ch-1.py b/challenge-279/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..6e1eb74a7a --- /dev/null +++ b/challenge-279/roger-bell-west/python/ch-1.py @@ -0,0 +1,22 @@ +#! /usr/bin/python3 + +def sortletters(a, n): + out = a.copy() + for i, l in enumerate(a): + out[n[i] - 1] = l + return "".join(out) + +import unittest + +class TestSortletters(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(sortletters(["R", "E", "P", "L"], [3, 2, 1, 4]), "PERL", 'example 1') + + def test_ex2(self): + self.assertEqual(sortletters(["A", "U", "R", "K"], [2, 4, 1, 3]), "RAKU", 'example 2') + + def test_ex3(self): + self.assertEqual(sortletters(["O", "H", "Y", "N", "P", "T"], [5, 4, 2, 6, 1, 3]), "PYTHON", 'example 3') + +unittest.main() diff --git a/challenge-279/roger-bell-west/python/ch-2.py b/challenge-279/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..480e58ab2e --- /dev/null +++ b/challenge-279/roger-bell-west/python/ch-2.py @@ -0,0 +1,24 @@ +#! /usr/bin/python3 + +def splitstring(a): + n = 0 + for cc in a: + match cc.lower(): + case 'a' | 'e' | 'i' | 'o' | 'u': + n += 1 + return n % 2 == 0 + +import unittest + +class TestSplitstring(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(splitstring("perl"), False, 'example 1') + + def test_ex2(self): + self.assertEqual(splitstring("book"), True, 'example 2') + + def test_ex3(self): + self.assertEqual(splitstring("goodmorning"), True, 'example 3') + +unittest.main() |
