Kodewick
Start learning →
Mini challenge←→0 / 100

The silver medal

#055Mini challengeListsConditions6 min

The high-jump results (in cm) are in a list. Write silver(heights) to return the second-best height: a jump as high as the winner's does not count as second. If everyone jumped the same, or the list is empty, return None.

Examples
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:
        # your code here: lower than best goes into others
        pass
    # your code here: None if others is empty, else its biggest
    return None
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.