La Biblioteca

Una biblioteca è una raccolta di informazioni, fonti, risorse e servizi. Fornisce accesso fisico o digitale a una vasta gamma di libri, DVD e altri materiali. È un vivace centro di conoscenza dove coesistono innumerevoli titoli, autori ed elementi multimediali. Il compito è creare un sistema software che rappresenti e gestisca accuratamente i diversi tipi di elementi disponibili in questa biblioteca.
Per rappresentare l'elemento generale della biblioteca, crea una classe LibraryItem. Ogni elemento della biblioteca ha un title, un author e un id. Ha anche un metodo chiamato __str__() che restituisce una stringa con questi dettagli nel formato "Title: {title}, Author: {author}, ID: {id}".
La biblioteca ospita due tipi di elementi: libri e DVD. Per rappresentare questi elementi, ti viene chiesto di creare due classi, Book e DVD, che ereditano dalla classe LibraryItem.
La classe Book deve avere un attributo aggiuntivo pages, che rappresenta il numero di pagine del libro. La classe DVD deve avere un attributo aggiuntivo duration, che rappresenta la durata del DVD in minuti.
Sovrascrivi il metodo __str__() in ogni sottoclasse per includere l'attributo aggiuntivo. Per la classe Book, il metodo dovrebbe restituire una stringa nel formato "Title: {title}, Author: {author}, ID: {id}, Pages: {pages}". Per la classe DVD, il metodo dovrebbe restituire una stringa nel formato "Title: {title}, Author: {author}, ID: {id}, Duration: {duration} minutes".
Ingresso
Uscita
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 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue