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. Ilrating
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'attributorating
.
Il numero inserito dovrebbe essere compreso tra0
e10
. 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 ilrating
èNone
, stampareNot Rated
invece diNone
.
Input | Output |
---|---|
| Title: Inception, Director: Christopher Nolan, Rating: 8 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB