0
0
LLDsystem_design~10 mins

Rating and review system in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Review class with a rating attribute.

LLD
class Review:
    def __init__(self, rating):
        self.[1] = rating
Drag options to blanks, or click blank then click option'
Arating
Bscore
Cvalue
Drate
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated attribute names like 'score' or 'value' which may confuse readers.
2fill in blank
medium

Complete the code to add a method that calculates the average rating from a list of reviews.

LLD
def average_rating(reviews):
    total = 0
    for review in reviews:
        total += review.[1]
    return total / len(reviews) if reviews else 0
Drag options to blanks, or click blank then click option'
Ascore
Brating
Cvalue
Drate
Attempts:
3 left
💡 Hint
Common Mistakes
Using an incorrect attribute name causing attribute errors.
3fill in blank
hard

Fix the error in the code that adds a new review to the system's review list.

LLD
class ReviewSystem:
    def __init__(self):
        self.reviews = []

    def add_review(self, review):
        self.reviews.[1](review)
Drag options to blanks, or click blank then click option'
Ainsert
Badd
Cappend
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' which is not a list method in Python.
Using 'extend' which expects an iterable, causing errors.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps user IDs to their average rating.

LLD
user_avg_ratings = {user_id: sum(r.rating for r in reviews) [1] len(reviews) for user_id, reviews [2] user_reviews.items()}
Drag options to blanks, or click blank then click option'
A//
B/
Cin
Dof
Attempts:
3 left
💡 Hint
Common Mistakes
Using integer division '//' which truncates decimals.
Using 'of' instead of 'in' causing syntax errors.
5fill in blank
hard

Fill all three blanks to filter reviews with rating above 3 and create a dictionary of user to their filtered reviews count.

LLD
filtered_counts = {user: len([r for r in reviews if r.[1] [2] [3]]) for user, reviews in user_reviews.items()}
Drag options to blanks, or click blank then click option'
Arating
B>
C3
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'score' instead of 'rating' causing attribute errors.
Using '<' instead of '>' causing wrong filtering.