Kodewick
开始学 →
小挑战←→0 / 100

第二名的成绩

#055小挑战列表条件约 6 分钟

跳高比赛的成绩(厘米)都在列表里。写 silver(heights),返回第二高的成绩:和第一名一样高的不算第二名。如果所有人都一样高,或者列表是空的,返回 None。

示例
silver([120, 135, 128])→128
silver([140, 140, 130])→130
silver([110, 110])→None
main.py
def silver(heights):
    if len(heights) == 0:
        return None
    best = max(heights)
    others = []
    for h in heights:
        # 在这里写:比 best 低的放进 others
        pass
    # 在这里写:others 是空的返回 None,不然返回其中最大的
    return None
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。