Kodewick
開始學 →
入門←→0 / 80

該澆水了

#033入門for plant, d in .items()約 3 分鐘

陽臺上的植物記在一個字典裡:{植物: 幾天沒澆水}。寫 thirsty_plants(days),返回 3 天或更久沒澆水的植物,按字典裡的順序排。都不用澆就返回 []。

示例
thirsty_plants({"fern": 4, "cactus": 10, "mint": 1})→['fern', 'cactus']
thirsty_plants({})→[]
main.py
def thirsty_plants(days):
    thirsty = []
    # 在這裡寫:用 items() 走一遍,天數夠 3 就把植物放進 thirsty
    return thirsty
Ctrl + Enter 也能執行
結果

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