diff options
| author | Abigail <abigail@abigail.be> | 2021-10-19 16:40:57 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-10-19 16:40:57 +0200 |
| commit | 71d3279fed60471b894f85006f0573eba5e0e66f (patch) | |
| tree | feab918c8159a0952d9f22d24990de01bce4d854 /challenge-135/abigail/python/ch-2.py | |
| parent | 6fbe2f4e31051b2ecc881d9f476c61fe08b5b43b (diff) | |
| download | perlweeklychallenge-club-71d3279fed60471b894f85006f0573eba5e0e66f.tar.gz perlweeklychallenge-club-71d3279fed60471b894f85006f0573eba5e0e66f.tar.bz2 perlweeklychallenge-club-71d3279fed60471b894f85006f0573eba5e0e66f.zip | |
Python solutions for week 135
Diffstat (limited to 'challenge-135/abigail/python/ch-2.py')
| -rw-r--r-- | challenge-135/abigail/python/ch-2.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-135/abigail/python/ch-2.py b/challenge-135/abigail/python/ch-2.py new file mode 100644 index 0000000000..93ba2921e2 --- /dev/null +++ b/challenge-135/abigail/python/ch-2.py @@ -0,0 +1,32 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput +import re + +w = [1, 3, 1, 7, 3, 9, 1] + +for line in fileinput . input (): + line = line . strip () + if re . search (r'^[0-9BCDFGHJKLMNPQRSTVWXYZ]{7}$', line): + check = 0 + for i in range (len (line)): + val = ord (line [i : i + 1]) + if val <= ord ("9"): + val = val - ord ("0") + else: + val = val - ord ("A") + 10 + check = check + w [i] * val + if check % 10 == 0: + print (1) + else: + print (0) + else: + print (0) |
