Movie Class

Create a Python class Movie that has the following attributes: title, director, and rating. The class should be able to manipulate these attributes through the following methods:
  • __init__(self, title, director): A constructor that takes a title and a director as input. The rating should be set to None initially (as the movie is not rated initially).
  • rate(self, rating): This method should take a number as input and assigns it to the rating attribute. The input number should be between 0 and 10. If the input is out of range, print an error message: Invalid rating. It should be between 0 and 10..
  • show_details(self): This method should print the details of the movie in the following format: Title: [title], Director: [director], Rating: [rating]. If the rating is None, print Not Rated instead of None.
Input
Output
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