diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-01-02 14:34:00 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-02 14:34:00 +0000 |
| commit | 171592004a80dc30e8d1d1d35fd82a9c9681a724 (patch) | |
| tree | 0ea7a2b1349848d076454cc973e59d21c53e8cba /challenge-145/sgreen/python/ch-1.py | |
| parent | db0755b8dd9daa003523cbcd53759ced09ae7dfd (diff) | |
| parent | 8bdcc1eac06889402d8b9beb3f1e7c467df9a4ff (diff) | |
| download | perlweeklychallenge-club-171592004a80dc30e8d1d1d35fd82a9c9681a724.tar.gz perlweeklychallenge-club-171592004a80dc30e8d1d1d35fd82a9c9681a724.tar.bz2 perlweeklychallenge-club-171592004a80dc30e8d1d1d35fd82a9c9681a724.zip | |
Merge pull request #5445 from simongreen-net/master
sgreen solutions to challenge 145
Diffstat (limited to 'challenge-145/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-145/sgreen/python/ch-1.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-145/sgreen/python/ch-1.py b/challenge-145/sgreen/python/ch-1.py new file mode 100755 index 0000000000..7c18890304 --- /dev/null +++ b/challenge-145/sgreen/python/ch-1.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import sys +import re + + +def main(inputs): + first_nums = list(map(int, re.findall(r'-?\d+', inputs[0]))) + second_nums = list(map(int, re.findall(r'-?\d+', inputs[1]))) + + if len(first_nums) != len(second_nums): + raise ValueError('Arrays are of different lengths') + + dots = [] + sums = [] + for i in range(len(first_nums)): + dots.append(f'({first_nums[i]} × {second_nums[i]})') + sums.append(first_nums[i] * second_nums[i]) + + print(' + '.join(dots) + + ' => ' + + ' + '.join(map(str, sums)) + + ' => ' + + str(sum(sums))) + + +if __name__ == '__main__': + main(sys.argv[1:]) |
