小游戏的排行榜只显示前三名。写 top_three(scores),返回最高的 3 个分数,从高到低。不到 3 个分数,就全部从高到低返回。
top_three(scores)
top_three([300, 950, 120, 700])
[950, 700, 300]
top_three([40, 80])
[80, 40]
def top_three(scores): ranked = sorted(scores) # 在这里写:从高到低排,然后取前 3 个 return ranked
写好了先点「运行」试试示例,没问题再点「提交」。
这一页要打开 JavaScript 才能写代码。