Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education