diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2024-08-31 15:35:44 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2024-08-31 15:35:44 +0100 |
| commit | c7ee461c41c0b7889dbe89b403935b960d49a31d (patch) | |
| tree | ed6ace3a7cc78cf324b8d15a88b4445d70f34594 /challenge-047 | |
| parent | 038c86e09d59d3754ab2814e568010d11ca4be89 (diff) | |
| download | perlweeklychallenge-club-c7ee461c41c0b7889dbe89b403935b960d49a31d.tar.gz perlweeklychallenge-club-c7ee461c41c0b7889dbe89b403935b960d49a31d.tar.bz2 perlweeklychallenge-club-c7ee461c41c0b7889dbe89b403935b960d49a31d.zip | |
Add Python solution to challenge 047
Diffstat (limited to 'challenge-047')
| -rw-r--r-- | challenge-047/paulo-custodio/python/ch-1.py | 27 | ||||
| -rw-r--r-- | challenge-047/paulo-custodio/python/ch-2.py | 22 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-047/paulo-custodio/python/ch-1.py b/challenge-047/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..caebfcb2b6 --- /dev/null +++ b/challenge-047/paulo-custodio/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env perl + +# Challenge 047 +# +# TASK #1 +# Roman Calculator +# Write a script that accepts two roman numbers and operation. It should then +# perform the operation on the give roman numbers and print the result. +# +# For example, +# +# perl ch-1.pl V + VI +# It should print +# +# XI + +import roman +import sys + +if len(sys.argv) != 4: + print("Usage: ch-1.py xxx +- xxx") +elif sys.argv[2] == "+": + print(roman.toRoman(roman.fromRoman(sys.argv[1])+roman.fromRoman(sys.argv[3]))) +elif sys.argv[2] == "-": + print(roman.toRoman(roman.fromRoman(sys.argv[1])-roman.fromRoman(sys.argv[3]))) +else: + print("Usage: ch-1.py xxx +- xxx") diff --git a/challenge-047/paulo-custodio/python/ch-2.py b/challenge-047/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..a0a80f18bc --- /dev/null +++ b/challenge-047/paulo-custodio/python/ch-2.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +# Challenge 047 +# +# TASK #2 +# Gapful Number +# Write a script to print first 20 Gapful Numbers greater than or equal to 100. +# Please check out the page for more information about Gapful Numbers. + +def is_gapful(n): + n1 = int(str(n)[0]) + n2 = int(str(n)[-1]) + div = n1*10+n2 + return n % div == 0 + +out = [] +n = 100 +while len(out) < 20: + if is_gapful(n): + out.append(n) + n += 1 +print(", ".join([str(x) for x in out])) |
