# This code implements a Library application that lets user store and # retrieve books from a shelf. # # Tasks: # - Fix storeNewBook, and getBook # - Can you add a way to see all books in the library? # - Make a way to update a book? # - Make sure you cannot add a book with the same title (using compare?) # import shelve from Book import * def storeNewBook(): 'Store a new book in the library' # Ask the user for the input needed to create a book title = raw_input('Title:') numPages = input('Num Pages:') author = raw_input('Author:') # Create the book newBook = Book(title, author, numPages) # Add the book into the shelf based on the title (make sure to lowercase the title) lowerCaseTitle = title.lower() library[lowerCaseTitle] = newBook def getBook(): 'Get information about a book from the library' print 'Get Book' # Get the title we want to see title = raw_input('Title: ') title = title.lower() # Look up the book in the library myBook = library[title] # Print out the book print myBook def updateBook(): 'Get the book from the library and update pieces of it' print 'UpdateBook' def main(): global library # Open the library library = shelve.open('lib', writeback=True) choice = 'z' while choice != 'q': print ''' ************************ MENU ------------------------ (s)tore a new book (g)et book info (u)pdate book info (q)uit ************************ ''' choice = raw_input('Enter choice:') if choice == 's': storeNewBook() elif choice =='g': getBook() elif choice =='u': updateBook() elif choice == 'q': None # Do nothing, but we know this was a valid option else: print '\n\nSorry, %s is not a valid option \n\n' %(choice) library.close() main()