Last active
February 22, 2022 04:27
-
-
Save phonemkyaw/ba6bbfcc300831861db9feea760e4293 to your computer and use it in GitHub Desktop.
Python function to calculate the star rating from a given list of ratings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calculate_star_rating(ratings): | |
"""This function calculates the star rating of the given list with array positions as | |
0 - 1 Star | |
1 - 2 Stars | |
2 - 3 Stars | |
3 - 4 Stars | |
4 - 5 Stars | |
""" | |
stars = [1,2,3,4,5] | |
return round(sum(list(map(lambda a,b: a*b, stars, ratings))) / sum(ratings), 2) | |
ratings = [100,200,300,400,500] | |
calculate_star_rating(ratings) | |
#3.67 |
Your function got ratings
but not used
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thats not clear code.