Question 1
a. Design a class called ISBN to represent an International Standard Book Number. The ISBN consists of 10 digits divided into 4 parts. For example, the ISBN 7 758871 47 5 represents the following information:
- The first part: The first digit "7" signifies the book is from a French-speaking country.
- The second part: "758871" identifies the publisher.
- The third part: "47" is the title number for the book.
- The fourth part: "5" is a check digit to indicate that the sum of the ISBN digits is 10.
The class should have a method to take input from the users and display it on the screen.
b. Design a Book class that represents relevant information about a book, including the book's title, authorName, publisherName, Address (remember the class we created in Question-1 has a relationship) and price. Find out the relationship between Book and ISBN and code accordingly.
def isValidISBN(isbn):
if len(isbn) != 10:
return False
_sum = 0
for i in range(9):
if 0 <= int(isbn[i]) <= 9:
_sum += int(isbn[i]) * (10 - i)
else:
return False
if(isbn[9] != 'X' and
0 <= int(isbn[9]) <= 9):
return False
_sum += 10 if isbn[9] == 'X' else int(isbn[9])
return (_sum % 11 == 0)
isbn = "007462542X"
if isValidISBN(isbn):
print('Valid')
else:
print("Invalid")
Comments
Leave a comment