0% found this document useful (0 votes)
15 views2 pages

Class Book

The document defines three classes: Book, BorrowableBook, and ReferenceBook, each with attributes and methods for displaying book information. BorrowableBook includes additional features for managing borrower details and due dates, while ReferenceBook includes a room number for location. Example instances of each class are created and their information is displayed.

Uploaded by

aaak85182
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Class Book

The document defines three classes: Book, BorrowableBook, and ReferenceBook, each with attributes and methods for displaying book information. BorrowableBook includes additional features for managing borrower details and due dates, while ReferenceBook includes a room number for location. Example instances of each class are created and their information is displayed.

Uploaded by

aaak85182
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

class Book:

def __init__(self, title, author, ISBN):


self.title = title
self.author = author
self.ISBN = ISBN

def display_info(self):
print(f"Book: {self.title}\n Author: {self.author} \n
ISBN: {self.ISBN}")

class BorrowableBook(Book):
def __init__(self, title, author, ISBN, borrower_name,
due_date):
super().__init__( title, author, ISBN)
self.__borrower_name = borrower_name
self.due_date = due_date

def get_borrower_name(self):
return self.__borrower_name

def set_borrower_name(self, new_borrower_name):


self.__borrower_name = new_borrower_name

def display_info(self):
super().display_info()
print(f"Borrower name: {self.__borrower_name}\n Due date:
{self.due_date}")

class ReferenceBook(Book):
def __init__(self, title, author, ISBN, room_number):
super().__init__( title, author, ISBN)
self.room_number = room_number

def display_info(self):
super().display_info()
print(f"Room number: {self.room_number} ")
book1 = Book("Python Basics", "John Doe", "123-456")
book2 = Book("Open", "Andre Agassi", "0307-978")

book_br = BorrowableBook("Data Science Essentials", "Alice


Smith","780-101","Alice", "15/12/2024")

book_re = ReferenceBook("Machine Learning Handbook", "Bob Lee",


"112-233", 205)

book1.display_info()
book2.display_info()
print("\nBorrowable Book:")

book_br.display_info()
print("\nReference Book:")

book_re.display_info()

You might also like