Movieクラス

PythonのクラスMovieを作成してください。このクラスは次の属性を持ちます:titledirectorrating。クラスは以下のメソッドを通じてこれらの属性を操作できるようにします:
  • __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]ratingNoneの場合は、Noneの代わりにNot Ratedと表示します。
入力
出力
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