跳高比赛的成绩(厘米)都在列表里。写 silver(heights),返回第二高的成绩:和第一名一样高的不算第二名。如果所有人都一样高,或者列表是空的,返回 None。
silver([120, 135, 128])→128silver([140, 140, 130])→130silver([110, 110])→Nonedef silver(heights):
if len(heights) == 0:
return None
best = max(heights)
others = []
for h in heights:
# 在这里写:比 best 低的放进 others
pass
# 在这里写:others 是空的返回 None,不然返回其中最大的
return None
写好了先点「运行」试试示例,没问题再点「提交」。