isbn-10 validity identifier

Here’s a program that does the isbn error checking.

#!/usr/bin/env python

#this program checks if isbn-10 numbers are valid

import sys

def usage():
  "You're using it wrong!"

  isbn = sys.argv[1].replace('-','')

isbnNum = isbn[0:9]
checksumPassed = int(isbn[9:])

sum = 0
index = 10
for i in isbnNum:
  sum += int(i)* index
  index -= 1
print "sum is ", sum
checksum = 11 - (sum % 11)

print 11 - checksum
if checksum == checksumPassed:
  print "isbn checksum is fine"
  print "isbn checksum error"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: