145k views
4 votes
At certain Olympic events, there are 5 judges. To determine an athlete’s final score for the event, the highest and lowest judges’ scores are discarded and then the average of the rest of the scores is calculated. Assume that the array 'Scores' contains the judges’ scores.

1. Write a function that accepts as an argument a list of scores and returns the athlete’s final score.
2. Add up all the scores in the array.
3. Find the highest and lowest scores and subtract them out.
4. Divide sum by len(Scores) – 2 and return as the average.

User Homam
by
7.7k points

1 Answer

2 votes

Final answer:

To calculate an athlete's final score, a function is written that takes a list of scores, discards the highest and lowest values, sums the remaining scores, and calculates the average. This is common for some Olympic events' score tabulation.

Step-by-step explanation:

The student's question involves writing a function to calculate the average score of an athlete after removing the highest and lowest scores given by judges, commonly used in some Olympic events. Here are the steps and the function to calculate the final score:

  1. Define the function to accept a list of scores.
  2. Find the highest and lowest scores using built-in functions like max() and min().
  3. Remove the highest and lowest scores from the total sum of scores.
  4. Calculate the average by dividing the adjusted sum by the number of remaining scores, which is the length of the original list minus 2 (since we discarded two scores).
  5. Return the final average score.

Here's an example of the function in Python:

def calculate_final_score(scores):
highest_score = max(scores)
lowest_score = min(scores)
adjusted_sum = sum(scores) - highest_score - lowest_score
final_score = adjusted_sum / (len(scores) - 2)
return final_score

To use this function, you would pass in the list of scores as an argument, and it will return the athlete’s final score.

User Unknown Artist
by
8.2k points