Clase Movie
Crea una clase de Python
Movie
que tenga los siguientes atributos: title
, director
y rating
. La clase debe manipular estos atributos a través de los siguientes métodos:__init__(self, title, director)
: Un constructor que recibe un título y un director como parámetros. El atributorating
debe establecerse inicialmente en None (ya que la película no está calificada al principio).
rate(self, rating)
: Este método acepta un número como entrada y lo asigna al atributorating
. El número debe estar entre0
y10
. Si el número está fuera de rango, imprime un mensaje de error:Invalid rating. It should be between 0 and 10.
.
show_details(self)
: Este método imprime los detalles de la película en el siguiente formato:Title: [title], Director: [director], Rating: [rating]
. Si elrating
esNone
, imprimeNot Rated
en lugar deNone
.
Entrada | Salida |
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