Books
The digital revolution has knocked at the doors of the grand library. They are transitioning from conventional books to e-books. The cataloging system is managed by a Python program using a
Book
class which stores attributes like title
, author
, and publication_year
.Your task is to create a subclass named
EBook
, which inherits from the Book
class. The EBook
class should have additional attributes like file_size
(in MB) and format
(like 'PDF', 'EPUB', 'MOBI', etc.).
The
Book
class includes a __str__()
method that returns a string including the title, author, and publication_year in the format: "Title: {title}, Author: {author}, Published: {publication_year}". You should override this __str__()
method in the EBook
class to return a string that includes the title, author, publication_year, file_size, and format in the following format: "Title: {title}, Author: {author}, Published: {publication_year}, Size: {file_size} MB, Format: {format}".Input | Output |
book = Book('To Kill a Mockingbird', 'Harper Lee', 1960); ebook = EBook('The Great Gatsby', 'F. Scott Fitzgerald', 1925, 1.5, 'PDF'); print(book); print(ebook) | Title: To Kill a Mockingbird, Author: Harper Lee, Published: 1960
Title: The Great Gatsby, Author: F. Scott Fitzgerald, Published: 1925, Size: 1.5 MB, Format: PDF |
Constraints
Time limit: 2.4 seconds
Memory limit: 512 MB
Output limit: 1 MB