Classe Movie
Crie uma classe Python
Movie
que possui os seguintes atributos: title
, director
e rating
. A classe deve ser capaz de manipular esses atributos através dos seguintes métodos:__init__(self, title, director)
: Um construtor que recebe um título e um diretor como parâmetros. Orating
deve ser inicialmente definido como None (já que o filme não está avaliado inicialmente).
rate(self, rating)
: Este método deve receber um número como entrada e atribuí-lo ao atributorating
. O número inserido deve estar entre0
e10
. Se o número estiver fora desse intervalo, imprima uma mensagem de erro:Invalid rating. It should be between 0 and 10.
.
show_details(self)
: Este método deve imprimir os detalhes do filme no seguinte formato:Title: [title], Director: [director], Rating: [rating]
. Se orating
forNone
, imprimaNot Rated
em vez deNone
.
Entrada | Saída |
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