Python3 How can I improve my code follow the instruction? In self. part in line6 to line10. I want to remake my code in the specified format: __title (string) __release_year (integer) __director (string) __ratings (list) Hint: initialize to empty list. __average_rating (float) Hint: initialize to 0. movie.py: class Movie: # Define attributes and methods for a Movie class, # as specified in the instructions # The attributes should be PRIVATE def __init__(self, title, release_year, director, ratings = [], avg_rating=0): self.__title = title self.__release_year = release_year self.__director = directo
Python3
How can I improve my code follow the instruction? In self. part in line6 to line10. I want to remake my code in the specified format:
- __title (string)
- __release_year (integer)
- __director (string)
- __ratings (list) Hint: initialize to empty list.
- __average_rating (float) Hint: initialize to 0.
movie.py:
class Movie:
# Define attributes and methods for a Movie class,
# as specified in the instructions
# The attributes should be PRIVATE
def __init__(self, title, release_year, director, ratings = [], avg_rating=0):
self.__title = title
self.__release_year = release_year
self.__director = director
self.__ratings = ratings
self.__average_rating = avg_rating
def __str__(self):
return ("Title: "+self.__title + " Year: " + str(self.__release_year) + " Director: " + self.__director)
def add_rating(self, rating):
self.__ratings.append(rating)
def calc_average_rating(self):
self.__average_rating = sum(self.__ratings) / len(self.__ratings)
def getRatings(self):
return self.__ratings
def getAverageRating(self):
return self.__average_rating
![movie.py
1
class Movie:
2
# Define attributes and methods for a Movie class,
as specified in the instructions
# The attributes should be PRIVATE
def _init_(self, title, release_year, director, ratings = [], avg_rating=0):
self._title
self.
3
#3
4
6.
title
_release_year
director
self._ratings = ratings
Laverage_rating
release_year
director
7
8.
self.
9.
10
self.
avg_rating
11
_str_(self):
return ("Title: "+self._title +
def add_rating(self, rating):
self._ratings.append( rating)
def calc_average_rating(self):
self._average_rating
def getRatings(self):
return self._ratings
def getAverageRating(self):
return self._average_rating
12
def
13
Year: " + str(self._release_year) +
" Director:
%3D
14
15
16
17
sum(self._ratings) / len(self._ratings)
18
19
20
21
22](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F909d4e96-ec45-4f89-986e-8cb112f8d100%2F9d29ff1d-ff7c-4999-9667-8ce0f31512a5%2Foxw1yms_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)