thon 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 I already created the program by using Python, but here is wha

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 4GZ
icon
Related questions
Question
100%

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

I already created the program by using Python, but here is what I need help with (in bold):
• Reading and writing data to a file(s). In other words, have the program to read ISBNs from a file and store the correct results in a file as well.

Can you include codes within my current program (included below) so that my program will read ISBNs from a file and store the correct results in a file as well?

* Please make sure to use the Python program when making out the code in specific. Thanks!

 

My current Python program:

def main():
      menu()

def 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 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':
           return

      elif command == '1' or command == '3':
           ISBN = input('Please enter the ISBN-10 number: ')
           ISBN = ISBN.replace('-', '')

           while len(ISBN) != 10:
                  print('Please make sure you have entered a number that 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':
           ISBN = input('Please enter the 13 digit number: ')
           ISBN = ISBN.replace('-','')

           while len(format(ISBN)) != 13:
                  print('Please make sure you have entered a number that 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))

      menu()

def check_10_digit(ISBN):
      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('Your ISBN-10 is valid.')

      else:
           print('Your ISBN-10 is NOT valid.')

def check_13_digit(ISBN):
       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('Your remainder is: ', digit, ', which means that your ISBN-13 is valid.')

      else:
            print('Your remainder is: ', digit, ', which means that your ISBN-13 is NOT valid.')

def convert_10_to_13(ISBN):
        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('The ISBN-10 number ', ISBN, 'is converted to the ISBN-13 number ', ISBN_New)

def convert_13_to_10(ISBN):
       if ISBN[:3] == '978':
             n = str(ISBN[3:-1])
       else :
             raise 'ISBN 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('The ISBN-13 number ', ISBN, 'is converted to the ISBN-10 number ', ISBN_New)

main()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage