Count a value
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
This one builds on a lesson you haven't finished yet. Do that lesson first:
Python Basics · Functions →
Count a value
Count how often one value appears in a list.
Loop over the list and compare each item with target. It is the counter pattern again, with the condition item == target, and it works for words as well as numbers.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Write count_value(items, target) that returns how many times target appears in items, without using .count().
Click Run to see the output here.