Review: Combine Loops and Function Inputs
Trace loop scope, nested repetitions, two accumulators and independent function calls.
Bring the unit skills together
Use these 4 new cases to check your reasoning. Choices are temporary and are not saved to an account, sent to staff or recorded as school grades. Download your current review choices before leaving or reloading.
The download contains your current choices and any checked feedback. Keep the separate transfer-task work in your own document; downloading its instructions does not mark it complete.
Use the skills in a new task
Write a function positive_stats(values) returning the count and sum of positive integers. Trace it for [1, −2, 4, 0]. Then repeat that fresh function call twice and add its returned sum to a separate grand_total initialized once at 0. Predict zero outer repeats as a test.
Work on paper or in your own document. Explain the choices you made.
- Give local count and total an initial 0 for each function call.
- Trace positive_stats to (2, 5).
- Initialize grand_total outside the outer repeat and trace 0 → 5 → 10.
- Explain that zero outer repeats leaves grand_total = 0.
Compare with a model response
positive_stats: count = 0; total = 0; for each x, if x > 0: count += 1; total += x; return (count, total). For [1, −2, 4, 0], states are (1,1), (1,1), (2,5), (2,5); return (2,5). Set grand_total = 0; repeat twice: call positive_stats afresh and add its returned total 5. Grand total is 10. Zero outer repeats returns 0.
A different response can also meet the criteria. Compare the evidence and reasoning, rather than copying the wording.