Kodewick
开始学 →
基础←→0 / 80

果园挑大苹果

#010基础函数循环约 5 分钟

果园给苹果称重,200 克以上(含 200)算大果。is_big 和 count_big 已经写好。把 count_if(items, check) 写完:check 是一个函数,对每一样调用它,数一数有几个得到 True。空列表就是 0。

示例
count_big([180, 210, 200, 150])→2
count_big([])→0
main.py
def is_big(weight):
    return weight >= 200


def count_if(items, check):
    n = 0
    for x in items:
        # 在这里写:check(x) 是 True,n 就加 1
        pass
    return n


def count_big(weights):
    return count_if(weights, is_big)
Ctrl + Enter 也能运行
结果

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