Python Day 13: Abstract Classes




Given a Book class and a Solution class, write a MyBook class that does the following:

Inherits from Book
Has a parameterized constructor taking these parameters:
Implements the Book class' abstract display() method so it prints these lines:



  1. from abc import ABCMeta, abstractmethod
  2. class Book(object, metaclass=ABCMeta):
  3. def __init__(self,title,author):
  4. self.title=title
  5. self.author=author
  6. @abstractmethod
  7. def display(): pass
  8. class MyBook(Book):
  9. def __init__(self, title, author, price):
  10. Book.__init__(self, title, author)
  11. self.price = price
  12. def display(self):
  13. print('Title: ' + self.title)
  14. print('Author: ' + self.author)
  15. print('Price: ' + str(self.price))
  16. title=input()
  17. author=input()
  18. price=int(input())
  19. new_novel=MyBook(title,author,price)
  20. new_novel.display()
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]


donate a cup of tea :)


Join Our Facebook Group

Share this solution






codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube