diff options
Diffstat (limited to 'challenge-254/sgreen/python')
| -rwxr-xr-x | challenge-254/sgreen/python/ch-1.py | 23 | ||||
| -rwxr-xr-x | challenge-254/sgreen/python/ch-2.py | 31 | ||||
| -rwxr-xr-x | challenge-254/sgreen/python/test.py | 22 |
3 files changed, 76 insertions, 0 deletions
diff --git a/challenge-254/sgreen/python/ch-1.py b/challenge-254/sgreen/python/ch-1.py new file mode 100755 index 0000000000..37c492575d --- /dev/null +++ b/challenge-254/sgreen/python/ch-1.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import sys + + +def three_power(n: int) -> bool: + # Get the closest integer to a cube root + i = round(abs(n) ** (1/3)) + + # Return true if this number is indeed a cube root + return i ** 3 == abs(n) + + +def main(): + # Convert input into integers + n = int(sys.argv[1]) + result = three_power(n) + print('true' if result else 'false') + + +if __name__ == '__main__': + # Convert input into integers + main() diff --git a/challenge-254/sgreen/python/ch-2.py b/challenge-254/sgreen/python/ch-2.py new file mode 100755 index 0000000000..eed9768157 --- /dev/null +++ b/challenge-254/sgreen/python/ch-2.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import sys + + +def reverse_vowels(s: str) -> str: + # Convert it to lower case + s = s.lower() + + # Extract the vowels + vowel_list = [c for c in s if c in 'aeiou'] + + new_string = '' + for c in s: + # If the character here is a vowel + if c in 'aeiou': + # ... get the last vowel + new_string += vowel_list.pop() + else: + new_string += c + + return new_string.capitalize() + + +def main(): + s = sys.argv[1] + print(reverse_vowels(s)) + + +if __name__ == '__main__': + main() diff --git a/challenge-254/sgreen/python/test.py b/challenge-254/sgreen/python/test.py new file mode 100755 index 0000000000..f9d9c15650 --- /dev/null +++ b/challenge-254/sgreen/python/test.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +import unittest +ch_1 = __import__('ch-1') +ch_2 = __import__('ch-2') + + +class TestClass(unittest.TestCase): + def test_ch_1(self): + self.assertTrue(ch_1.three_power(27)) + self.assertTrue(ch_1.three_power(0)) + self.assertFalse(ch_1.three_power(6)) + + def test_ch_2(self): + self.assertEqual(ch_2.reverse_vowels('Raku'), 'Ruka') + self.assertEqual(ch_2.reverse_vowels('Perl'), 'Perl') + self.assertEqual(ch_2.reverse_vowels('Julia'), 'Jaliu') + self.assertEqual(ch_2.reverse_vowels('Uiua'), 'Auiu') + + +if __name__ == '__main__': + unittest.main() |
