# Python list totals

Instructor-authored reference material for a TutorFlow creation trial.

## Python list totals

Beginner practice with lists, for loops, and a running total.
Goal: calculate a total and explain each step.
Prerequisites: integer variables and print().
Use Python 3. Do not use sum() for this exercise.

## Add each value once

A list keeps values in order. A for loop visits each value.
Initialize total before the loop so earlier additions are kept.
For [3, 5, 2], total changes from 0 to 3, then 8, then 10.

```python
numbers = [3, 5, 2]
total = 0
for number in numbers:
    total = total + number
print(total)
```

## Check different inputs

[3, 5, 2] gives 10.
[] gives 0 because the loop never runs.
[-2, 5] gives 3.
[4] gives 4.
Try each input and explain why the answer changes.

## Find the misplaced reset

This code prints 2 instead of 10.
Explain which line resets the running total.
Move that line before the loop and run the code again.

```python
numbers = [3, 5, 2]
for number in numbers:
    total = 0
    total = total + number
print(total)
```

## Review questions

1. What is the final total for [3, 5, 2]?
2. Why must total = 0 appear before the loop?
3. What happens for an empty list in the correct code?
4. Write a loop for [-2, 5] without using sum().
Answers: 10; preserve previous additions; print 0; start at 0 and add each value.
