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
Step by step
Solved in 2 steps with 2 images