The Library
A library is a collection of information, sources, resources, and services. It provides physical or digital access to a vast array of books, DVDs, and other materials. It is a bustling hub of knowledge where countless titles, authors, and multimedia items coexist. The task is to create a software system that accurately represents and handles the different types of items available in this library.
To represent the general library item, create a
LibraryItem
class. Each library item has a title
, an author
, and an id
. It also has a method called __str__()
that returns a string with these details in the format "Title: {title}, Author: {author}, ID: {id}".The library houses two types of items: books and DVDs. To represent these items, you are asked to create two classes,
Book
and DVD
, that inherit from the LibraryItem
class.The
Book
class should have an additional attribute pages
, representing the number of pages the book has. The DVD
class should have an additional attribute duration
, representing the duration of the DVD in minutes.Override the
__str__()
method in each subclass to include the additional attribute. For the Book
class, the method should return a string in the format "Title: {title}, Author: {author}, ID: {id}, Pages: {pages}". For the DVD
class, the method should return a string in the format "Title: {title}, Author: {author}, ID: {id}, Duration: {duration} minutes".Input | Output |
book = Book('The Great Gatsby', 'F. Scott Fitzgerald', 'B001', 180); print(book); dvd = DVD('Jurassic Park', 'Steven Spielberg', 'D001', 127); print(dvd); | Title: The Great Gatsby, Author: F. Scott Fitzgerald, ID: B001, Pages: 180
Title: Jurassic Park, Author: Steven Spielberg, ID: D001, Duration: 127 minutes |
Constraints
Time limit: 2.4 seconds
Memory limit: 512 MB
Output limit: 1 MB