Keep a Count and a Sum
Use two accumulators to describe selected list values.
Supplied materials
- Paper and pencil; an adult may read aloud. No device, account or purchase is needed.
Learn the idea
A count and a sum answer different questions. A count adds one for each accepted item; a sum adds that item’s value. Keep both variables in a trace instead of reusing one name for two purposes. The supplied values are integers, and this exercise selects values greater than 0.
Algorithm: count = 0; total = 0; for each x in [4, 0, −2, 3], if x > 0, set count = count + 1 and total = total + x; return count and total. A rejected item changes neither accumulator. The final pair describes how many positive values there are and their combined amount.
- Make columns x, x > 0?, count and total.
- Record starting count = 0 and total = 0.
- For each positive x, perform both different additions.
- Check final count against positive-item quantity and total against their sum.
See the method in action
After x = 4: (count, total) = (1, 4). After 0 and −2: still (1, 4). After 3: (2, 7). Returned pair is (2, 7), not (7, 2).
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
See the answer and explanation
(2, 7)
Only 2 and 5 satisfy x > 0. Their count is 2 and sum is 7; zero and −1 change neither.
Take it further
Change the selection to x ≥ 0 for the original list. Expected pair: (3, 7). Zero increases the count by 1 but adds 0 to the total.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.