question 82 Functions · easy
The average rating is always the first rating
average_rating should return the mean of a film's ratings as a float, so [4, 5, 3, 5] gives 4.25, and None when there are no ratings. Instead it returns the first rating, and a film with no ratings crashes it. Find and fix every bug.
Function
average_rating(ratings)ratingsa list of whole-number ratings from 1 to 5
Returnsthe mean as a float (
4.0, not 4), or None for an empty listExamples
callaverage_rating([4, 5, 3, 5])returns4.25
callaverage_rating([2, 4])returns3.0
callaverage_rating([])returnsNone