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 |
---|---|
| Title: The Great Gatsby, Author: F. Scott Fitzgerald, ID: B001, Pages: 180 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB