Lesson guide
What this Python exercise practices
Sum List Numbers is a beginner practice lesson that focuses on loops, iteration, counters. It is designed to be solved in about 8 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Lists or strings
- Basic for loop syntax
Difficulty and time
- Level
- Beginner
- Estimated time
- 8 minutes
Related public exercises
Summary
Use a loop to accumulate the sum of numbers in a list.
Problem statement
Write a function sum_list(nums) that receives a list of numbers (ints or floats) and returns their sum. If the list is empty, return 0. Implement the summation using a loop (for or while) and an accumulator variable — do not use Python's built-in sum() in your implementation.
Task
Implement summation by iterating through a list and accumulating a total without using the built-in sum().
Examples
Simple sum
Input
sum_list([1, 2, 3, 4])
Output
10
Explanation
1 + 2 + 3 + 4 = 10
Input format
A single list named nums passed as the function argument.
Output format
A single numeric value (int or float) equal to the sum of the list elements.
Constraints
- nums length may be 0 or more. - Elements are numbers (int or float). - Use a loop and accumulator; don't use sum() in starter implementation.
Samples
Sample input 0
sum_list([0, -1, 5])
Sample output 0
4
Explanation 0
0 + (-1) + 5 = 4
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.