Classe Movie

Crea una classe Python Movie che ha i seguenti attributi: title, director e rating. La classe dovrebbe essere in grado di manipolare questi attributi attraverso i seguenti metodi:
  • __init__(self, title, director): Un costruttore che prende in input un titolo e un regista. Il rating dovrebbe essere inizialmente impostato a None (poiché il film non è inizialmente valutato).
  • rate(self, rating): Questo metodo dovrebbe accettare un numero come input e assegnarlo all'attributo rating. Il numero inserito dovrebbe essere compreso tra 0 e 10. Se l'input è fuori intervallo, stampare un messaggio di errore: Invalid rating. It should be between 0 and 10..
  • show_details(self): Questo metodo dovrebbe stampare i dettagli del film nel seguente formato: Title: [title], Director: [director], Rating: [rating]. Se il rating è None, stampare Not Rated invece di None.
Input
Output
m = Movie('Inception', 'Christopher Nolan'); m.rate(8); m.show_details(); m.rate(12); m.show_details(); dh = Movie('The Dark Knight', 'Christopher Nolan'); dh.show_details()
Title: Inception, Director: Christopher Nolan, Rating: 8 Invalid rating. It should be between 0 and 10. Title: Inception, Director: Christopher Nolan, Rating: 8 Title: The Dark Knight, Director: Christopher Nolan, Rating: Not Rated
 

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