question 123 Comprehensions · easy
Share of the vote
An election page shows each candidate's share of the vote as a percentage. Given the vote counts in ballot order, return the percentages in the same order.
Function
vote_shares(votes)votesa list of whole numbers, 0 or more
Returnsa new list of floats: each count × 100 ÷ the total of all counts, in the same order
Ruleswhen nobody has voted yet (the total is 0) every share is
0.0; no candidates gives []Examples
callvote_shares([50, 30, 20])returns[50.0, 30.0, 20.0]
callvote_shares([3, 1])returns[75.0, 25.0]
callvote_shares([])returns[]