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. Theratingshould 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 theratingattribute.
The input number should be between0and10. 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 theratingisNone, printNot Ratedinstead ofNone.
Input | Output |
|---|---|
| Title: Inception, Director: Christopher Nolan, Rating: 8 |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB