Skip to content

Instantly share code, notes, and snippets.

@Centzilius
Created September 2, 2014 17:21
Show Gist options
  • Save Centzilius/0629916dbc0e5e46d257 to your computer and use it in GitHub Desktop.
Save Centzilius/0629916dbc0e5e46d257 to your computer and use it in GitHub Desktop.
ISBN Checknumber Calculator
# -*- coding: UTF-8 -*-
import sys
class InvalidInput(Exception):
def __init__(self, error):
self.error = error
def __str__(self):
return self.error
try:
ISBNInput = input("ISBN Nummer: ")
if len(str(ISBNInput)) != 9:
raise InvalidInput(ISBNInput)
a, b, c, d, e, f, g, h, i = str(ISBNInput)
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
f = int(f)
g = int(g)
h = int(h)
i = int(i)
checknumcalc = (a*1+b*2+c*3+d*4+e*5+f*6+g*7+h*8+i*9)%11
if checknumcalc == 10:
pruefziffer = "X"
else:
pruefziffer = str(checknumcalc)
print("ISBN Prüfziffer: " + pruefziffer)
except KeyboardInterrupt:
sys.exit(1)
except InvalidInput:
print "Deine Eingabe ist ungültig."
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment