Kodewick
開始學 →
小挑戰←→0 / 112

第二名的成績

#055小挑戰h < best約 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 也能執行
結果

寫好了先點「執行」試試示例,沒問題再點「提交」。