HI All, PFB question are part of python OOPS lab.
Help complete the complete the program
Open the file bookshop.py, and complete the code so that the Book class has
two new methods add_author and add_chapter.
Also, add a new subclass BookMeta, which has a price property and a rating method.
The price is related to the rating.
Follow the comments in the code for the exact actions these methods should perform.
OUTPUT:
Book info: Two Scoops of Django, 5 stars, 12.0
Book properties: {‘title’: ‘Two Scoops of Django’, ‘author’: ‘Greenfeld’, ‘chapter_number’: ‘3’, ‘chapter_title’: ‘Async Views’}
BookInfo properties: {‘title’: ‘Two Scoops of Django’, ‘author’: None, ‘info’: True, ‘price’: 12.0, ‘stars’: 5}
class Book:
def init(self, title):
self.title = title
self.author = None
def add_author(self, name):
# add author property
self.author = name
def add_chapter(self, number, title):
# add properties chapter_number and chapter_title
self.chapter_number = number
self.title = title
class BookInfo(Book):
def init(self, title, price, info=False):
Book.init(self, title)
# add properties price and info
self.price = price
self.info = info
self.stars = 0
def rating(self, stars):
try:
# check if existing stars are less than new stars
# and if new stars are greater than 4
# adjust new price by a 20% increase
if (self.stars)
...
# update the stars property
...
except Exception as e:
print(e, "Please try again")
Create a book object titled ‘Two Scoops of Django’
…
Add the author ‘Greenfeld’
…
Add a chapter 3, with title ‘Async Views’
…
Create a book_info object titled ‘Two Scoops of Django’
with a price of 10, and info set to True
…
Give the book_info a rating of 5 stars
…
print("Book info: “, end=” ")
Print book_info’s title, stars and price
print(
…, str(book_info.stars) + " stars",
…, sep=", "
)
Print all properties of book and book_info objects
print("Book properties: ", …)
print("BookInfo properties: ", …)