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!"

try:
  isbn = sys.argv[1].replace('-','')
except:
  usage()

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"
else:
  print "isbn checksum error"

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s