lesson

The Accumulator Pattern

objective: Preserve running state across iterations by initializing it at the correct lifetime.
Task type: fix broken code
The provided sum_list(nums) implementation is broken. Repair it so it returns the total of every number in the list.
fix this code
Fix the existing code so every authored test passes.
  • Returns 0 for an empty list
  • Returns the single value for a one-item list
  • Sums [1, 2, 3] to 6
  • Handles negative numbers
Go deeper

Lesson resources

Finding resources…
sum_list.pyattempt 0
1
2
3
4
5
6