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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Software products
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education