#583 · Lists · Intermediate · Review the AI's code · 60 XP · about 7 min
Someone asked an AI assistant: "Write a function that drops the highest and lowest judges' scores and averages the rest." This is its answer. It looks right, but it has a bug.
In some sports a performance is marked by several judges, and the highest and lowest marks are thrown out to keep things fair. judged_score(scores) should leave out one highest and one lowest score, then return the average of the scores that are left, rounded to 2 decimal places. The caller's list must not change: the original marks are still needed for the scoreboard.
judged_score([7.5, 9.0, 6.0, 8.0]) # returns 7.75 judged_score([5, 5, 5]) # returns 5.0 judged_score([10, 2, 6, 8, 4]) # returns 6.0
In the first example 9.0 and 6.0 are left out, and the average of 7.5 and 8.0 is 7.75.
scores has 3 to 20 numbers from 0 to 10.First solves only, ranked by stars and then time.