runtime
416 / 500
question 416 pandas Foundations · medium

The average rating that is too low

rating_summary should return the average of the ratings customers actually gave, and how many reviews have a rating. Reviews without a rating (missing) must not count. The product team says the averages look too low and the counts too high. Fix it. With no ratings at all, the average is None.

Functionrating_summary(records)
recordsa list of {"review_id": …, "rating": int or None}
Returns{"average": float or None, "rated": int}
Examples
callrating_summary([{'review_id': 'R000103', 'rating': 5}, {'review_id': 'R000140', 'rating': 2}, {'review_id': 'R000188', 'rating': None}, {'review_id': 'R000201', 'rating': 4}])returns{'average': 3.6666666666666665, 'rated': 3}
callrating_summary([{'review_id': 'R000103', 'rating': 5}, {'review_id': 'R000188', 'rating': None}])returns{'average': 5, 'rated': 1}
callrating_summary([{'review_id': 'R1', 'rating': 1}, {'review_id': 'R2', 'rating': 2}])returns{'average': 1.5, 'rated': 2}

Loading your progress…

The average rating that is too low — Python practice · Runtime