Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Book(object): A Book Object. def __init__(self, title, author, pub_yr='Unknown'): self.title = title self.author = author self.pub_yr = pub_yr def __repr__(self): return '' % (self.title)

class Book(object): """A Book Object.""" def __init__(self, title, author, pub_yr='Unknown'): self.title = title self.author = author self.pub_yr = pub_yr def __repr__(self): return '' % (self.title) 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 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 ########### WRITE YOUR SCRIPT HERE # Details on what the script should include are in the skills assessment # instructions. b1 =Book("The Bell Jar", "Sylvia Plath", 1963) #printing book1 information print " Book b1 : ",b1 print 'Book b1 Publication year : ',b1.pub_yr b2 =Book("Anna Karenina", "Leo Tolstoy") #printing b2 information print' ' print "Book b2 : ",b2 print 'Book b2 Publication year : ',b2.pub_yr #Instantiate a library object l = Library() print(l) # Adding books to Library l.add_book(b1); l.add_book(b2); print " " # Listing books l.list_books();

Question: Finish the empty_library method in the Library class. It should remove all the books from a library. Call the empty_library method at the bottom of the script you wrote in Part One. Then, call the method that lists the books in a library and verify that it shows that the library is now empty.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

Solve Prob. 1079 using Mohrs circle.

Answered: 1 week ago

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago