Question: Python3 Previous week's code: def isbn_gendigit(string): res = 0 for i in range(0,9): res = res + (i+1)*(ord(string[i])-48) res = res % 11 print(string +

Python3

Previous week's code:

def isbn_gendigit(string): res = 0 for i in range(0,9): res = res + (i+1)*(ord(string[i])-48) res = res % 11 print(string + str(res)) return None

(1) Better Check Digit

(a) Revise function isbn_gendigit to check for the case where the check digit (10th digit) is 10, for example, when the 9-digit ISBN is 020141452. When the check digit is 10, the character added to the 9-digit ISBN should be X.

Check that your code runs correctly for the following test cases:

>>> isbn_gendigit('020141452')

020141452X

>>> isbn_gendigit('058132921')

058132921X

Also make sure that your code works correctly for cases when the check digit is 0:

>>> isbn_gendigit('068333923')

0683339230

>>> isbn_gendigit('567890123')

5678901230

(b) Write a different function, isbn_check, with one parameter, isbn, that determines whether the ISBN is well-formed. That is, isbn_check should return True when the ISBN check digit (10th digit) is correct, and False otherwise.

For example,

>>> isbn_check('097522980X')

True >>> isbn_check('0681319216')

True

>>> isbn_check('5678901230')

True >>> isbn_check('5678901231')

False

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!