← Back to challenges

Star Ratings

PythonHardarrayslogicmathnumbers

Instructions

Given a list of five values, calculate the average star rating, rounded to two decimal places. The list contains user votes per star, so the first element [0] contains the number of 1-star ratings and the last element [4], the number of 5-star ratings.

Return the average score in [brackets], followed by a space and asterisks' * to represent the star rating, rounded to the nearest whole star.

Examples

star_rating([55, 67, 98, 115, 61]) ➞ "[3.15] ***"

star_rating([0, 2, 0, 1, 23]) ➞ "[4.73] *****"

star_rating([16, 17, 23, 40, 45]) ➞ "[3.57] ****"

Notes

Round stars to whole stars.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.