Use python write a function that takes the scores of all players as keyword arguments and returns the name of the player with maximum score after calculating the scores with the truncated mean scoring(remove one highest score and one lowest score). Do not import anything
eg.
def bp(**player_scores):
>>> bp(ab=[9.6, 9, 9.8, 9.9], bc=[9.0, 9.5, 9.9],cd=[10.0, 9.8, 10.0, 9.5, 9.6])
'cd'
>>> bp(ab=[3.8, 3.5, 3.2], bc=[4.0, 3.6, 3.0])
'bc'
def bp(**player_scores): best_player = '' best_score = 0 for player, scores in player_scores.items(): total = 0 smallest = None largest = None for score in scores: total += score if largest is None or score > largest: largest = score if smallest is None or score < smallest: smallest = score truncated_mean_score = (total - smallest - largest) / (len(scores) - 2) if truncated_mean_score > best_score: best_score = truncated_mean_score best_player = player return best_player # Testing the function here. ignore/remove the code below if not required print(bp(ab=[9.6, 9, 9.8, 9.9], bc=[9.0, 9.5, 9.9], cd=[10.0, 9.8, 10.0, 9.5, 9.6])) print(bp(ab=[3.8, 3.5, 3.2], bc=[4.0, 3.6, 3.0]))
Get Answers For Free
Most questions answered within 1 hours.