IN PYTHON: Define a class named Book. Each instance of Book should have three in
ID: 3732116 • Letter: I
Question
IN PYTHON:
Define a class named Book. Each instance of Book should have three instance variables: title, author, checked_out.
The Book constructor should take two arguments, title and author. Use these to set the initial values for the corresponding instance variables. The instance variable checked_out should be set to False.
add these methods to the class Book:
checkitout (no arguments): sets the book's checked_out attribute to True
checkitin (acceptsa Library instance as its argument): 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.
tobechecked (no arguments): Return True if the checked_out attribute is False and False otherwi
Explanation / Answer
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(self) == 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
ob = Book('ABCDEF' , 'XYZ')
print('Title :', ob.title)
print('Author :', ob.author)
print('To be checked :', ob.tobechecked())