Answer to Question #295009 in Python for dv13

Question #295009

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.  

 


1
Expert's answer
2022-02-08T07:54:13-0500
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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS