Complete the code to define a Review class with a rating attribute.
class Review: def __init__(self, rating): self.[1] = rating
The attribute to store the rating should be named rating for clarity and consistency.
Complete the code to add a method that calculates the average rating from a list of reviews.
def average_rating(reviews): total = 0 for review in reviews: total += review.[1] return total / len(reviews) if reviews else 0
The method accesses the rating attribute of each review to sum ratings correctly.
Fix the error in the code that adds a new review to the system's review list.
class ReviewSystem: def __init__(self): self.reviews = [] def add_review(self, review): self.reviews.[1](review)
The append method adds a single item to the list, which is correct here.
Fill both blanks to create a dictionary comprehension that maps user IDs to their average rating.
user_avg_ratings = {user_id: sum(r.rating for r in reviews) [1] len(reviews) for user_id, reviews [2] user_reviews.items()}The division operator / calculates the average, and in is used to iterate over dictionary items.
Fill all three blanks to filter reviews with rating above 3 and create a dictionary of user to their filtered reviews count.
filtered_counts = {user: len([r for r in reviews if r.[1] [2] [3]]) for user, reviews in user_reviews.items()}The code filters reviews where the rating is greater than 3 using the > operator.