Kodewick
开始学 →
入门←→0 / 80

该浇水了

#033入门字典循环约 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 也能运行
结果

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