IN PYTHON ADD THE FOLLOWING TO THE LIBRARY CLASS getBooksYouCanCheckOut (no argu
ID: 3732206 • Letter: I
Question
IN PYTHON
ADD THE FOLLOWING TO THE LIBRARY CLASS
getBooksYouCanCheckOut (no arguments besides self):
- Return a list of every book in the library that can be checked out. Books should be in the same order in which they were added to the library.
class Library:
def __init__ (self):
self.books = []
self.tornPageTolerance = 10
def addBook(self, book):
self.books.append(book)
def findBooksBy(self,author):
found = []
for book in self.books:
if book.author == author:
found.append(book)
return found
def willAccept(self, book):
isit = isinstance(book,PaperBook)
if isit == True:
if book.numTornPages < self.tornPageTolerance:
return True
else:
return True
Explanation / Answer
class Library:
def __init__ (self):
self.books = []
self.tornPageTolerance = 10
def addBook(self, book):
self.books.append(book)
def findBooksBy(self,author):
found = []
for book in self.books:
if book.author == author:
found.append(book)
return found
def willAccept(self, book):
isit = isinstance(book,PaperBook)
if isit == True:
if book.numTornPages < self.tornPageTolerance:
return True
else:
return True
def getBooksYouCanCheckOut(self):
arr = []
for book in self.books:
# if book is not already checked out
# then we can check out this book
if book.checked_out == False:
arr.append(book)
return arr
class Book:
# constructor
def __init__(self, title = '', author = ''):
self.title = title
self.author = author
self.checked_out = False
# checkitout (no arguments): sets the book's checked_out attribute to True
def checkitout(self):
self.checked_out = True
# call the library's willAccept() method on the current book.
# If library will accept it, set the checked_out attribute of the book to False
# Otherwise, do not modify it.
def checkitin(self, ob):
if ob.willAccept() == True:
self.checked_out = False
# Return True if the checked_out attribute is False and False otherwise
def tobechecked(self):
return self.checked_out == False
class Library:
def __init__ (self):
self.books = []
self.tornPageTolerance = 10
def willAccept(self, book):
isit = isinstance(book,PaperBook)
if isit == True:
if book.numTornPages < s