Movieクラス
PythonのクラスMovie
を作成してください。このクラスは次の属性を持ちます:title
、director
、rating
。クラスは以下のメソッドを通じてこれらの属性を操作できるようにします:
__init__(self, title, director)
: タイトルと監督名を引数に取るコンストラクタです。rating
は初期状態ではNone
に設定します(映画は最初は評価されていないため)。rate(self, rating)
: 数値を入力として受け取り、それをrating
属性に割り当てます。入力された数値は0
から10
の間である必要があります。範囲外の場合はエラーメッセージを表示します:Invalid rating. It should be between 0 and 10.
。show_details(self)
: 映画の詳細を次の形式で表示します:Title: [title], Director: [director], Rating: [rating]
。rating
がNone
の場合は、None
の代わりにNot Rated
と表示します。
入力 | 出力 |
---|---|
| 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