Lesson guide
What this Python exercise practices
Compute Running Total 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
Summary
Practice accumulating values across a list to produce running totals.
Problem statement
Given a list of integers nums, compute the running total list where the i-th element of the result is the sum of nums[0] through nums[i]. Use loops to iterate the input list and accumulate the sum incrementally.
Task
Given a list of numbers, return a new list where each element is the running total up to that index.
Examples
Basic running total
Input
compute_running_total([1, 2, 3])
Output
[1, 3, 6]
Explanation
The running totals are 1, 1+2=3, 1+2+3=6.
Input format
A single function call compute_running_total(nums) where nums is a list of integers.
Output format
Return a list of integers representing the running totals.
Constraints
0 <= len(nums) <= 10000. Each number fits in Python's integer type.
Samples
Sample input 0
compute_running_total([5, -2, 7])
Sample output 0
[5, 3, 10]
Explanation 0
Running totals: 5, 5+(-2)=3, 3+7=10.
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.