Kodewick
Start learning →
Basic←→0 / 80

Picking big apples

#010BasicFunctionsLoops5 min

The orchard weighs its apples; 200 grams or more counts as big. is_big and count_big are written. Finish count_if(items, check): check is a function, so call it on each item and count how many give True. An empty list gives 0.

Examples
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:
        # your code here: if check(x) is True, add 1 to n
        pass
    return n


def count_big(weights):
    return count_if(weights, is_big)
Ctrl + Enter runs too
Result

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