Question: class Library(object): A collection of book objects. def __init__(self): self.books = [] def __repr__(self): return ' ' % (len(self.books)) def list_books(self): List all the books
class Library(object): """A collection of book objects."""
def __init__(self): self.books = []
def __repr__(self): return '
def list_books(self): """List all the books in the library."""
if len(self.books) == 0: print "Library is empty." return for book in self.books: print book.title print ' Author:', book.author print ' Published:', book.pub_yr print
def add_book(self, book): """Add a book to the library."""
if not isinstance(book, Book): raise Exception('Please enter a Book Object to add to the library') self.books.append(book) print 'Added: %s' % (book.title)
def empty_library(self): """Remove all books from the library.""" pass
Question: Instantiate a library object
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
