Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions