curriculum/challenges/english/blocks/daily-coding-challenges-python/697a49e6ff50d756c9b69362.md
Given an array of judge scores and optional penalties, calculate the final score for a figure skating routine.
The first argument is an array of 10 judge scores, each a number from 0 to 10. Remove the highest and lowest judge scores and sum the remaining 8 scores to get the base score.
Any additional arguments passed to the function are penalties. Subtract all penalties from the base score to get the final score.
compute_score([10, 8, 9, 6, 9, 8, 8, 9, 7, 7], 1) should return 64.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compute_score([10, 8, 9, 6, 9, 8, 8, 9, 7, 7], 1), 64)`)
}})
compute_score([10, 10, 10, 10, 10, 10, 10, 10, 10, 10]) should return 80.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compute_score([10, 10, 10, 10, 10, 10, 10, 10, 10, 10]), 80)`)
}})
compute_score([10, 8, 9, 10, 9, 8, 8, 9, 10, 7], 1, 2, 1) should return 67.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compute_score([10, 8, 9, 10, 9, 8, 8, 9, 10, 7], 1, 2, 1), 67)`)
}})
compute_score([8.0, 8.5, 9.0, 8.5, 9.0, 8.0, 9.0, 8.5, 9.0, 8.5], 0.5, 1.0) should return 67.5.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compute_score([8.0, 8.5, 9.0, 8.5, 9.0, 8.0, 9.0, 8.5, 9.0, 8.5], 0.5, 1.0), 67.5)`)
}})
compute_score([6.0, 8.5, 7.0, 9.0, 7.5, 8.0, 6.5, 9.5, 7.0, 8.0], 1.5, 0.5, 0.5) should return 59.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(compute_score([6.0, 8.5, 7.0, 9.0, 7.5, 8.0, 6.5, 9.5, 7.0, 8.0], 1.5, 0.5, 0.5), 59)`)
}})
def compute_score(judge_scores, *penalties):
return judge_scores
def compute_score(judge_scores, *penalties):
sorted_scores = sorted(judge_scores)
base_score = sum(sorted_scores[1:9])
total_penalty = sum(penalties)
return base_score - total_penalty