From 08557d1d13ff13b0048147f492e0ab2d10d5f081 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sun, 16 Feb 2020 17:14:19 +0100 Subject: Challenge 047 Python solutions LK --- challenge-047/lubos-kolouch/python/ch-1.py | 31 ++++++++++++++++++++++++++++++ challenge-047/lubos-kolouch/python/ch-2.py | 9 +++++++++ 2 files changed, 40 insertions(+) create mode 100644 challenge-047/lubos-kolouch/python/ch-1.py create mode 100644 challenge-047/lubos-kolouch/python/ch-2.py diff --git a/challenge-047/lubos-kolouch/python/ch-1.py b/challenge-047/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..873c78af2a --- /dev/null +++ b/challenge-047/lubos-kolouch/python/ch-1.py @@ -0,0 +1,31 @@ +#! python3 +from roman import toRoman, fromRoman +import sys + + +class RomanConvertor: + + def roman_magic(self, v1, op, v2): + + rom_v1 = str(fromRoman(v1)) + rom_v2 = str(fromRoman(v2)) + + operation = rom_v1+op+rom_v2 + + return toRoman(eval(operation)) + + def main(self, v1, op, v2): + + return self.roman_magic(v1.upper(), op, v2.upper()) + + +if __name__ == '__main__': + v1, op, v2 = sys.argv[1:] + rom_conv = RomanConvertor() + print(rom_conv.main(v1, op, v2)) + +# tests + +rom_conv = RomanConvertor() +assert rom_conv.main('I', '+', 'II') == 'III' +assert rom_conv.main('II', '-', 'I') == 'I' diff --git a/challenge-047/lubos-kolouch/python/ch-2.py b/challenge-047/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..bfaa3f97f2 --- /dev/null +++ b/challenge-047/lubos-kolouch/python/ch-2.py @@ -0,0 +1,9 @@ +#!python3 + +count = 0 +for i in range(100, 10001): + if i % int(str(i)[0]+str(i)[2]) == 0: + print(i) + count += 1 + if count == 20: + break -- cgit