Question

Introduction: Ten digit ISBN numbers are created so that the first nine digits are information digits...

Introduction:

Ten digit ISBN numbers are created so that the first nine digits are information digits and the last digit is a check digit. T

his last number helps people notice and correct mistakes that might be made in recording the information digits.

The same is true for thirteen digit ISBN numbers. Here is a ten digit ISBN number: 0-13-149498-8.

The digit 0 indicates the book is written for English-speaking people.

The number 13 and the number 149498 identify the publisher and the book published by that publisher. The last digit, the 8, is the check digit.

It was chosen in the following way: each digit is given a weight by using the digits 1 to 10 and counting left to right. These weights are added. The sum is: 0(1) + 1(2) +3(3) + 1(4) + 4(5) + 9(6) + 4(7) + 9(8) + 8(9) + __ (The digits of the ISBN information numbers are listed in order from left to right and weighted by counting up from 1 to 9.) The check digit is chosen to be a number from 0 to 10 so that this weighted sum is a multiple of 11. That is, the sum must be divisible by 11. (If the check digit turns out to be 10 then in this case an X is displayed representing the Roman numeral for 10.) Let us see what sum we have so far with these particular nine information digits: 0(1) + 1(2) +3(3) + 1(4) + 4(5) + 9(6) + 4(7) + 9(8) + 8(9) = 0 + 2 + 9 + 4 + 20 + 54 + 28 + 72 + 72 = 261 The check digit 8 was chosen because 261 is between 253 and 264 (multiples of 11) and 261 is 8 more than 253. The only possible number from 0 to 10 to use as a check digit is 8. Thus we have: A ten digit ISBN number: 0-13-149498-8 If you know the ten digit ISBN number you can calculate the thirteen digit ISBN number. Simply start the thirteen digit ISBN number with 978, then re-calculate the check digit. For example, 0-13-149498-8 becomes 978-0-13-149498-? Calculating the check digit for the thirteen digit ISBN number is done differently than for the ten digit ISBN number. Below is the way to calculate the thirteen digit ISBN check digit. Note that on a thirteen digit ISBN number the weighted numbers are different: 1 3 1 3 1 3 1 3 1 3 1 3 9(1) + 7(3) + 8(1) + 0(3) + 1(1) +3(3) + 1(1) + 4(3) + 9(1) + 4(3) + 9(1) + 8(3) + __ =9 + 21 + 8 + 0 + 1 + 9 + 1 + 12 + 9 + 12 + 9 + 24 =115

The sum must be divisible by 10 for a thirteen digit ISBN. The check digit 5 was chosen because 115 divided by 10 is 11 with remainder 5. The remainder is the check digit. Thus we have: A thirteen digit ISBN number: 978-0-13-149498-5.

Write a python program which displays a simple menu as follows:

Python ISBN Conversion Menu

1.Verify the check digit of an ISBN-10

2.Verify the check digit of an ISBN-13

3.Convert an ISBN-10 to an ISBN-13

4.Convert an ISBN-13 to an ISBN-10

5.Exit

While for loops a must/if elif statements needed.

My code seems to be severely lacking at the moment. Could use all the help I can get to move in the right direction.

I hope the extra information helps.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
CODE:
def check10(ISBN): 
    s ,t = 0 , 1
    for i in ISBN:
        if not i == '-':
            s += t*int(i)
            t += 1
    t = 1
    while True:
        if t*11>s:
            break
        t+=1
    return (s - (t-1)*11) 
    
def check13(ISBN):
    if not ISBN[:3] == '978':
        print('Not verified')
        return 
    
    s,t = 0,1
    for i in ISBN:
        if not i == '-':
            if t%2==0:
                s+=3*int(i)
            else:
                s+=1*int(i)
            t+=1

    return s%10

def convertTo10(ISBN):
    ISBN = ISBN[4:-2]
    cbit = check10(ISBN)
    ISBN = ISBN +'-'+str(cbit)
    print(ISBN)
def convertTo13(ISBN):
    ISBN = '978-'+ISBN[:-2]
    cbit = check13(ISBN)
    ISBN = ISBN+'-'+str(cbit)
    print(ISBN)
        
        
            
        
while True:            
    print('Python ISBN Conversion Menu')
    print('1. Verify the check-digit of an ISBN-10')
    print('2. Verify the check-digit of an ISBN-13')
    print('3. Convert an ISBN-10 to ISBN-13')
    print('4. Convert an ISBN-13 to ISBN-10')
    print('5. Exit')
    ch = int(input('Enter choice: '))
    if ch == 5:
        print('Thank You')
        break
    ISBN = input('Enter ISBN number: ')
    check=ISBN[-1]
    if check == 'X':
        check = 10
    else:
        check = int(check)
        
    if ch==1:
        if check10(ISBN[:-2]) == check:
            print('Check bit Verified')
        else:
            print('Check bit does not verify')
            print()
    elif ch == 2:
        if check13(ISBN[:-2]) == check:
            print('Check bit Verified')
        else:
            print('Check bit does not verify')
            print()
    elif ch == 3:
        convertTo13(ISBN)
        print()
    elif ch == 4:
        convertTo10(ISBN)
        print()
    else:
        print('Wrong choice')

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Introduction: Ten digit ISBN numbers are created so that the first nine digits are information digits...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using c++ A ten diglt ISBN number uses a checksum as its last diglt to verlfy...

    Using c++ A ten diglt ISBN number uses a checksum as its last diglt to verlfy the first nine digits are valid. Before 2007, all ISBN numbers were composed like this, such as: e-20-5e8005-7 or 1-234-56789-X The first nine digits are assigned by a book's publisher and the last digit is calculated by "weighted sum (described below). The X stands for the checksum value of 10, in order to represent ten as a single digit. You must write a program...

  • Description: An ISBN-10 (International Standard Book Number) consists of 10 digits: didzdzdad5d6d7d8d9d1o. The last digit, dio,...

    Description: An ISBN-10 (International Standard Book Number) consists of 10 digits: didzdzdad5d6d7d8d9d1o. The last digit, dio, is a checksum, which is calculated from the other nine digits using the following formula: (d, x 1 + d2 x 2 +d3 x 3 + da x4 + ds x 5 + de x 6 + d7 x 7+ d3 x 8+dex 9) % 11 If the checksum is 10, the last digit is denoted as X according to the ISBN-10 convention. Write...

  • A phone number is an ordered string of ten digits. Each digit is one of 0,...

    A phone number is an ordered string of ten digits. Each digit is one of 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. (a) How many phone numbers are there that do not contain any zeros? (b) How many phone numbers are there that start with 216 or 440? (c) How many phone numbers are there that start or end with 3? (d) What is the smallest number of phone numbers that guarantee at least nine of...

  • 1. (a) (i) How many different six-digit natural numbers may be formed from the digits 2,...

    1. (a) (i) How many different six-digit natural numbers may be formed from the digits 2, 3, 4, 5, 7 and 9 if digits may not be repeated? (ii) How many of the numbers so formed are even? (iii) How many of the numbers formed are divisible by 3? (iv) How many of the numbers formed are less than 700,000? (b) JACK MURPHY’s seven character password consists of four let- ters chosen from the ten letters in his name (all...

  • Please tell me whether my answers are correct or not. If not please tell me why...

    Please tell me whether my answers are correct or not. If not please tell me why and give me a guide to solving the problem correctly. Thanks! 3 Check Digits: ISBN In this problem, we'll look at a real-world applications of check-digits International Standard Book Numbers (ISBNS) are 10-digit codes (did2...dio) which are assigned by the publisher. These 10 digits contain information about the language, the publisher, and the number assigned to the book by the publisher. Additionally, the last...

  • 13. For how many three digit numbers (100 to 999) is the sum of the digits...

    13. For how many three digit numbers (100 to 999) is the sum of the digits even? (For example, 343 has an even sum of digits: 3+4+3 = 10 which is even.) Find the answer and explain why it is correct in at least two different ways.

  • A large collection of one-digit random numbers should have about 50% odd and 50% even digits...

    A large collection of one-digit random numbers should have about 50% odd and 50% even digits because five of the ten digits are odd (1, 3, 5, 7, and 9) and five are even (0, 2, 4, 6, and 8) a. Find the proportion of odd-numbered digits in the following lines from a random number table. Count carefully. 9 0 49 0 5 0 7 8 1 7 8 3 4 5 0 7 1 5 7 5 1 2...

  • Banks issue credit cards with 16 digit numbers. If you've never thought about it before you...

    Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4, MasterCard numbers start with 51 through 55, American Express starts with 34 or 37, etc. Automated systems can use this number to tell which company...

  • Please fix my code so I can get this output: Enter the first 12-digit of an...

    Please fix my code so I can get this output: Enter the first 12-digit of an ISBN number as a string: 978013213080 The ISBN number is 9780132130806 This was my output: import java.util.Scanner; public class Isbn { private static int getChecksum(String s) { // Calculate checksum int sum = 0; for (int i = 0; i < s.length(); i++) if (i % 2 == 0) sum += (s.charAt(i) - '0') * 3; else sum += s.charAt(i) - '0'; return 10...

  • Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit...

    Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT