Question

In: Computer Science

(Business: check ISBN-13) ISBN-13 is a new standard for indentifying books. It uses 13 digits d1d2d3d4d5d6d7d8d910d11d12d13...

(Business: check ISBN-13)

ISBN-13 is a new standard for indentifying books. It uses 13 digits d1d2d3d4d5d6d7d8d910d11d12d13 . The last digit d13 is a checksum, which is calculated from the other digits using the following formula:

10 - (d1 + 3*d2 + d3 + 3*d4 + d5 + 3*d6 + d7 + 3*d8 + d9 + 3*d10 + d11 + 3*d12) % 10

If the checksum is 10, replace it with 0. Your program should read the input as a string. Display “incorrect input” if the input is incorrect.

Sample Run 1

Enter the first 12 digits of an ISBN-13 as a string: 978013213080

The ISBN-13 number is 9780132130806

Sample Run 2

Enter the first 12 digits of an ISBN-13 as a string: 978013213079

The ISBN-13 number is 9780132130790.

In Python.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#code

#method to validate the input
#returns true if isbn is a 12 digit number

def isValidInput(isbn):
   #if length is not 12, returns False
   
if len(isbn)!=12:
        return False
   
#defining a string of digits
   
digits='0123456789'
   
#loops through each character in isbn
   
for i in isbn:
        #if i is not a digit, returns False
       
if not i in digits:
            return False
    return True
#all checks passed

#method to find the checksum, given the validated isbn

def findChecksum(isbn):
    #converting isbn into a list of digits
   
digits=[int(i) for i in isbn]
    #variable to store the sum of digits
   
temp=0
    #looping through digits
   
for i in range(len(digits)):
        #if i is an even index,simply adding digit at index i to temp
       
if i%2==0:
            temp+=digits[i]
        #otherwise, multiplying current element by 3 and adding
       
else:
            temp+=3*digits[i]
    #finding result of temp modulo 10
   
mod=temp%10
    #finding checksum by subtracting from 10
   
checksum=10-mod
    #returning 0 if checksum is 10.
   
if checksum==10:
        return 0
   else:
        #returning checksum as it is
       
return checksum

if __name__ == '__main__':
    #getting input, validating, printing results
   
isbn=input('Enter the first 12 digits of an ISBN-13 as a string: ')
    if isValidInput(isbn):
        checksum=findChecksum(isbn)
        isbn_13=isbn+str(checksum)
        print('The ISBN-13 number is',isbn_13)
    else:
        print('incorrect input')

#output (two runs)

Enter the first 12 digits of an ISBN-13 as a string: 978013213080

The ISBN-13 number is 9780132130806



Enter the first 12 digits of an ISBN-13 as a string: 978013213079

The ISBN-13 number is 9780132130790

Related Solutions

CIS- Python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10....
CIS- Python (Business: check ISBN-10) An ISBN-10 (International Standard Book Number) consists of 10 digits: d1d2d3d4d5d6d7d8d9d10. The last digit, d10, is a checksum, which is calculated from the other nine digits using the following formula: (d1 * 1 + d2 * 2 + d3 * 3 + d4 * 4 + d5 * 5 + d6 * 6 + d7 * 7 + d8 * 8 + d9 * 9) % 11 If the checksum is 10, the last digit...
Write an ISBN Validator in C language What are ISBN? ISBN, or International Standard Book Number,...
Write an ISBN Validator in C language What are ISBN? ISBN, or International Standard Book Number, is a numeric identifier for commercially printed books. Prior to 2007, they had 10 digits, but all newly issued ISBN use 13 digits. They are used to uniquely identify a book and consist of several portions. These include the registrant group, publisher, title, and a check digit. The registrant group indicates where the publisher is located. For example a registrant group of 0 or...
Teen Book Review: The grieving teen: A guide for teenagers and their frends. ISBN: 0684868040 ISBN-13:...
Teen Book Review: The grieving teen: A guide for teenagers and their frends. ISBN: 0684868040 ISBN-13: 9780684868042 Authors:Helen FitzGerald THE FOLLOWING QUESTIONS ARE NOT CONTENT FROM THE BOOK BUT THOUGHTS FROM THE BOOK Recently many publishers have responded to the need for books that are designed to help adults discuss a difficult topic, death, with young children, and/or teens. You are to select one book (many are on Amazon), written for teens, and evaluate it based on what we have...
Topic is cryptography 10.increment the digits 858 of the ISBN of the text (ISBN13: 9780890068588) to...
Topic is cryptography 10.increment the digits 858 of the ISBN of the text (ISBN13: 9780890068588) to be 859. Then, by trial and error, change the check-sum (the last digit of the ISBN), to identify the title of the next book published by Artech House.
Principles of Marketing, 15th Edition, Philip T Kotler, Gary Armstrong ISBN-10: 0-13-308404-3 ISBN-13: 978-0-13-308404-7 I need...
Principles of Marketing, 15th Edition, Philip T Kotler, Gary Armstrong ISBN-10: 0-13-308404-3 ISBN-13: 978-0-13-308404-7 I need the answer to this book. 1. Expalin why brand equity is important to the seller. Does ESPN have strong brand equity? How does its brand equity relate to its brand value?
C++ Write a definition for a structure type for records for books. The record contains ISBN...
C++ Write a definition for a structure type for records for books. The record contains ISBN number, price, and book cover (use H for Hard cover and P for paper cover). Part of the problem is appropriate choices of type and member names. Then declare two variables of the structure. Write a function called GetData use the structure as function argument to ask the user to input the value from the keyboard for structure variables.
Is 100202345X a valid ISBN number? If not, what would the correct check digit have to...
Is 100202345X a valid ISBN number? If not, what would the correct check digit have to be ? Solve the congruence 121x ≡ 5 mod 350.
I need answers for Chapter 5 Problem 28. Render ISBN # 13: 978-0-13-45316-1. Problem Reads: sales...
I need answers for Chapter 5 Problem 28. Render ISBN # 13: 978-0-13-45316-1. Problem Reads: sales of industrial vacuum cleaners at R. Lowenthal supply Co. over the past 13 months are as follows: sales ($1,000s) Month. First row is 11 sales Month January. Need the following a) using a moving average with three periods, determine the demand for vacuum cleaners for next Feb. also (B), (C), (d) answers? this problem can be found on p. 179. in textbook Quantitative Analysis...
ISBN: 13: 9780133083576 The Practice of Public Relations, 12th edition, by Fraser P. Seitel Prentice-Hall 2014...
ISBN: 13: 9780133083576 The Practice of Public Relations, 12th edition, by Fraser P. Seitel Prentice-Hall 2014 / Chapter 3 or 4 What is the relationship between public relations and public opinion?
A textbook publisher for books used in business schools believes that the number of books sold...
A textbook publisher for books used in business schools believes that the number of books sold is related to the number of campus visits to decision makers made by their sales force. A sampling of the number of sales calls made and the number of books sold is shown in the following table. # OF SALES CALLS MADE ----- # OF BOOKS SOLD 25 375 15 250 25 525 45 825 35 550 25 575 25 550 35 575 25...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT