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 atributo rating 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 atributo rating. El número debe estar entre 0 y 10. 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 el rating es None, imprime Not Rated en lugar de None.
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

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