fork download
  1. score_A_B_1 = [[90.0, 97.0, 75.0, 92.0],[90.0, 97.0, 75.0, 92.0]]
  2. score_A_B_2 = [[100.0, 92.0, 98.0, 100.0],[100.0, 92.0, 98.0, 100.0]]
  3. score_A_B_3 = [[0.0, 87.0, 75.0, 22.0],[0.0, 87.0, 75.0, 22.0]]
  4.  
  5. scores = [score_A_B_1,score_A_B_2,score_A_B_3]
  6.  
  7. # Return the average of the number in the list
  8. def average(lst_of_numbers):
  9. return float(sum(lst_of_numbers))/len(lst_of_numbers)
  10.  
  11. # Return a weighted average of all list passed as parameter
  12. # The weight is calculate as 100% divided by the lenght of the list
  13. # eg. if the lenght of score_A_B = 2 ==> 100 / 2 ==> 50
  14. # but we need a percentage so
  15. # 50 / 100 ==> 0.5
  16. # the weight of each element will 0.5
  17. def get_weighted_average(score_A_Bs):
  18. weighted_average = 0
  19. for score_A_B in score_A_Bs:
  20. weighted_average += average(score_A_B) * (100 / len(score_A_Bs)/100)
  21.  
  22. return weighted_average
  23.  
  24. # Return the average of the all list
  25. def get_score_average(scores):
  26. return average([get_weighted_average(score) for score in scores])
  27.  
  28.  
  29. scores_average = get_score_average(scores)
  30. print(scores_average)
Success #stdin #stdout 0.03s 9440KB
stdin
Standard input is empty
stdout
77.33333333333333