Python

Python Exercise: Compute Checksum Digit for an ISBN Number

In this video, we’ll write a Python program that takes a 9-digit integer, computes the checksum, and prints the 10-digit ISBN number.

Background Information:

The International Standard Book Number (ISBN) is a 10 digit code that uniquely specifies a book. The rightmost digit is a checksum digit which can be uniquely determined from the other 9 digits from the condition that d1 + 2*d2 + 3*d3 + … + 10*d10 must be a multiple of 11 (here di denotes the ith digit from the right). The checksum digit d1 can be any value from 0 to 10: the ISBN convention is to use the value X to denote 10. Example: the checksum digit corresponding to 020131452 is 5 since is the only value of d1 between 0 and and 10 for which d1 + 2*2 + 3*5 + 4*4 + 5*1 + 6*3 + 7*1 + 8*0 + 9*2 + 10*0 is a multiple of 11.

Futher information:

Notice the 9-digit integer 020131452 in reverse oder:

2*2 + 3*5 + 4*4 + 5*1 + 6*3 + 7*1 + 8*0 + 9*2 + 10*0 = 83

What number between 0 and 10 should be added to 83 so that it is divisible by 11?

Since 88 is the next number that is divisible by 11, the checksum number is 5:

88 – 83 = 5

Verified by MonsterInsights