You are on page 1of 3

class Book:

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


self._title = title
self._author = author
self._pages = pages

@property
def title(self):
return self._title

@property
def author(self):
return self._author

@property
def pages(self):
return self._pages

@title.setter
def title(self, new_title):
self._title = new_title

@author.setter
def author(self, new_author):
self._author = new_author

@pages.setter
def pages(self, new_pages):
self._pages = new_pages

my_book = Book("The Hobbit", "John Ronald Reuel Tolkien", 287)

print(my_book.title)
print(my_book.author)
print(my_book.pages)
class Book:
def __init__(self, title: str, author: str, pages: int):
self.__title = title
self.__author = author
self.__pages = pages

def get_title(self):
return self.__title

class EBook(Book):
def __init__(self, title, author, pages):
super().__init__(title, author, pages)
def get_format(self):
return self.get_title().split(".")[-1]

book1 = EBook("Harry Potter and the Sorcerer's Stone", "J.K. Rowling",


320)
print(book1.get_format())

class AbstractBook:
def display_details(self):
pass
class Book(AbstractBook):
def __init__(self, title: str, author: str, pages: int):
self.__title = title
self.__author = author
self.__pages = pages
def get_title(self):
return self.__title
def display_details(self):
return f"""

Title: {self.__title}
Author: {self.__author}
Pages: {self.__pages}
"""
class EBook(Book):
def __init__(self, title, author, pages):
super().__init__(title, author, pages)
def get_format(self):
return self.get_title().split(".")[-1]

book1 = Book("The Interpretation of Dreams", "Sigmund Freud", 688)


print(book1.display_details())

You might also like