Question

Write a program in Python that asks the user for the ISBN of the book in...

Write a program in Python that asks the user for the ISBN of the book in the format xxx-x-xxx-xxxxx-x.

To validate:

  1. Initialize a total to 0
  2. Have the program remove the dashes so that only the 13 digits are left in the ISBN string
  3. for each index of the first 12 digits in the 13 digit ISBN string
  4. get the digit at the current index as an integer
  5. If the current index is an even number, add the digit to the total otherwise add the digit times 3 to the total. So look at the index to determine what should be added to the total
  6. After all digits are processed, the checksum will be 10 - ( total mod 10)
  7. If the checksum is 10, make it 0.
  8. If the checksum matches the last digit in the ISBN, the ISBN is valid, otherwise it is not. Display an appropriate message
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

isbn=input("Enter ISBN in following format xxx-x-xxx-xxxxx-x: ")

total=0

isbnWithoutDash=""

for ch in isbn:
if ch.isdigit():
isbnWithoutDash+=ch

lastDigit=int(isbnWithoutDash[len(isbnWithoutDash)-1])

isbnWithoutDash=isbnWithoutDash[:-1]


for ch in isbnWithoutDash:
num=int(ch)
if(num%2==0):
total+=num
else:
total+=3*num

checksum=10-(total%10)

if checksum==10:
checksum=0
if checksum==lastDigit:
print("Valid")
else:
print("Invalid")

output

code snaps

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Write a program in Python that asks the user for the ISBN of the book in...
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
  • In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python: Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes...

    In Python Write a well-documented (commented) program that asks the user for a 9-digit integer, computes its checksum, and then prints the corresponding ISBN number. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 + ... + 10d10 must be a multiple of 11 (here di denotes the ith...

  • Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type...

    Using the above described algorithm, create a program that: (IN PYTHON) 1.Asks the user which type of credit card he/she would like to find the checksum for. 2. Based on the user's choice of credit card, asks the user for the n digits of the credit card. [Get the input as a string; it's easier to work with the string, so don't convert to an integer.] 3. Using the user's input of the n digits, finds the last digit of...

  • Please write code in Python! You are asked to implement the following checksum formula to validate...

    Please write code in Python! You are asked to implement the following checksum formula to validate an identifi- cation number given to you. The formula works as follows. Using the original number, double the value of every other digit. Then add the values of the individual digits together (if a doubled value now has two digits, add the digits individually). The identification number is valid if the resulting sum is divisible by 10. Write a function called validateID that takes...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Write a C++ program that will read in an ISBN-10 ID, and determines whether the tenth...

    Write a C++ program that will read in an ISBN-10 ID, and determines whether the tenth digit is the valid checksum of the first nine digits. The program reads in purported ID, and finishes execution once it has printed out what it's read in, plus either VALID or INVALID. Cannot use getline function. a) Processing stops after ten digits, even if there are more digits on the line of input. The

  • Write a C++ program that asks for the following information about a book order from the...

    Write a C++ program that asks for the following information about a book order from the console: • Title • Author • ISBN (hint: careful about what data type to use - validate 9 or 13 characters) • Price (validate number < 400) • Quantity (number of books to purchase – validate > 0 and < 100) • Fiction/Non-Fiction (‘N’ or ‘F’ - validate) • Genre (‘R’ romance, ‘D’ drama, ‘M’ mystery – validate) Make use of the following data...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • Design a program in pseudocode that asks the user to enter a string containing a series...

    Design a program in pseudocode that asks the user to enter a string containing a series of ten single-digit numbers with nothing separating them. The program should display the sum of all the single digit numbers in the string except for the highest value digit. You may only use one main module and one sorting function; otherwise, do not modularize your program. For example, if the user enters 5612286470, the sum would be 33. (0+1+2+2+4+5+6+6+7) If there are multiple highest...

  • 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...

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