Write a python program which displays a simple menu as follows: Python ISBN Conversion Menu 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 Convert an ISBN-13 to an ISBN-10 4. 1. 5. Exit Please remember to use what you have learned during the semester such as: Functions and/or Value Returning Functions If structures or logic structures IF/Elif/ELSE Data structures i.e. File input/output String manipulations i.e. string slicing and lists, etc. Modules Loops i.e. WHILE loops or FOR loops

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

I need some help fixing this code. I need it to let me enter the ISBN number witht the dashes and find the check number my code is below Ill like my teachers direction as a refernce.

def main():
while True:
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 an ISBN-13")
print('4. Convert an ISBN-13 to an ISBN-10')
print('5. Exit')
command = input("Enter the Command (1-5): ")
if command == '5':
break
elif command == '1' or command == '3':
# get 10 digit input
ISBN = input("Please enter the ISBN-10 number: ")
ISBN = ISBN.replace('-', '')
while len(ISBN) != 10:
print("Please make sure you have entered a number which is exactly 10 characters long.")
ISBN = input("Please enter the ISBN number: ")
ISBN = ISBN.replace('-', '')
print(format(ISBN))

if command == '1':
print(check_10_digit(ISBN))
else:
print(convert_10_to_13(ISBN))
elif command == '2' or command == '4':
# get 13 digit input
ISBN = input("Please enter the 13 digit number: ")
ISBN = ISBN.replace('-', '')
while len(ISBN) != 13:
print("Please make sure you have entered a number which is exactly 13 characters long")
ISBN = input("Please enter the 13 digit number: ")
ISBN = ISBN.replace('-', '')

if command == '2':
print(check_13_digit(ISBN))
else:
print(convert_13_to_10(ISBN))



def check_10_digit(ISBN):
#This portion of code will pull the entered ISBN from my Menu() statement and add all the numbers.
#It will then find the remainder of those numbers, if th remainder is 0 it will say the ISBN is valid
#If it comes back with the formula having a remainder, it will say NOT Valid.
digit = 0
for i in range(len(ISBN)):
n = ISBN[i]
num = int(n)
digit += (i+1) * num
d10 = digit % 11

print("Your ISBN-10 is: ", ISBN, "with a remainder of", str(d10))
if d10 == 0:
print("\nYour ISBN-10 is valid")
else:
print("\nYour ISBN-10 is NOT valid")

def check_13_digit(ISBN):
#Calcualte the ISBN Check Digit for 13 digit numbers
n = str(ISBN)
digit = 0
for i in range(len(n)):
if i % 2 == 0:
digit += int(n[i])
else:
digit += int(n[i]) * 3
digit = digit % 10

if digit == 0:
print("\nYour remainder is: ", digit, "your ISBN-13 is Valid")
else:
print("\nYour remainder is: ", digit, "your ISBN-13 is NOT Valid")

def convert_10_to_13(ISBN):
#Convert an ISBN-10 number to a ISBN-13 number
ISBN_13 = '978' + ISBN[:-1]
n = str(ISBN_13)
digit = 0
for i in range(len(n)):
if i % 2 == 0:
digit += int(n[i])
else:
digit += int(n[i]) * 3
digit = digit % 10

ISBN_New = str(ISBN_13) + str(digit)
print("\nThe ISBN-10 number ", ISBN, "is converted to the ISBN-13 number ", ISBN_New)

def convert_13_to_10(ISBN):
#Convert an ISBN-13 number to a ISBN-10 number
if ISBN[:3] == '978':
n = str(ISBN[3:-1])
else :
raise Exception("\nISBN is not convertible.")

digit = 0
for i in range(len(n)):
if i % 2 == 0:
digit += int(n[i])
else:
digit += int(n[i]) * 3
digit = 10 - (digit % 10)

ISBN_New = str(n) + str(digit)
print("\nThe ISBN-13 number ", ISBN, "is converted to the ISBN-10 number ", ISBN_New)

main()

Ten digit ISBN numbers are created so that the first nine digits are information digits and the last
digit is a check digit. This 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:
13131 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
Transcribed Image Text:Ten digit ISBN numbers are created so that the first nine digits are information digits and the last digit is a check digit. This 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: 13131 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
Please remember to use what you have learned during the semester such as:
Functions and/or Value Returning Functions
If structures or logic structures IF/Elif/ELSE
Data structures i.e. File input/output
String manipulations i.e. string slicing and lists, etc.
Modules
Loops i.e. WHILE loops or FOR loops
Transcribed Image Text: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 Please remember to use what you have learned during the semester such as: Functions and/or Value Returning Functions If structures or logic structures IF/Elif/ELSE Data structures i.e. File input/output String manipulations i.e. string slicing and lists, etc. Modules Loops i.e. WHILE loops or FOR loops
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY