aboutsummaryrefslogtreecommitdiff
path: root/challenge-162/eric-cheung/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-04-25 23:06:23 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-04-25 23:06:23 +0100
commitbbee5c1408c2b451c1e801b7c2fceda4a3b55243 (patch)
tree0eeff28170a963222865edaa144c0d0cbc2f9215 /challenge-162/eric-cheung/python/ch-1.py
parent532aa12e1c9375daea3dda8ea514abeb434b8949 (diff)
downloadperlweeklychallenge-club-bbee5c1408c2b451c1e801b7c2fceda4a3b55243.tar.gz
perlweeklychallenge-club-bbee5c1408c2b451c1e801b7c2fceda4a3b55243.tar.bz2
perlweeklychallenge-club-bbee5c1408c2b451c1e801b7c2fceda4a3b55243.zip
- Added guest solutions by Eric Cheung.
Diffstat (limited to 'challenge-162/eric-cheung/python/ch-1.py')
-rwxr-xr-xchallenge-162/eric-cheung/python/ch-1.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/challenge-162/eric-cheung/python/ch-1.py b/challenge-162/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..e2586a422c
--- /dev/null
+++ b/challenge-162/eric-cheung/python/ch-1.py
@@ -0,0 +1,17 @@
+
+def getCheckDigit_13(strISBN_12):
+
+ arrFactor = [1, 3]
+ nSum = 0
+ for nLoop in range(0, len(strISBN_12)):
+ nSum = nSum + int(strISBN_12[nLoop]) * arrFactor[nLoop % 2]
+
+ return (10 - nSum % 10) % 10
+
+
+strISBN = "978030640615"
+
+strISBN_Nu = "{}-{}-{}-{}".format(strISBN[:3], strISBN[3:4], strISBN[4:7], strISBN[7:])
+
+## print ("ISBN-13 check digit for " + strISBN + " is " + str(getCheckDigit_13(strISBN)))
+print ("ISBN-13 check digit for " + strISBN_Nu + " is " + str(getCheckDigit_13(strISBN)))