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. O rating 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 atributo rating. O número inserido deve estar entre 0 e 10. 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 o rating for None, imprima Not Rated em vez de None.
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

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