Add them all
Inputs
values is a list of 0 to 12 whole numbers, each from -50 to 50.
Your tasks
- Create a number
totalthat starts at 0. - Use a loop to visit every number in
valuesand add it tototal. - Complete
listSumso it returnstotal. Return it, do not print it.
Example
With values = [4, -2, 9, 1], listSum returns 12.
Rules
- An empty list adds up to 0.
Test data
TEST DATA 1: values is [4, -2, 9, 1]
TEST DATA 2: values is []
Practice focus
One pass over a list to add, count, find the biggest and the smallest. Scanning an array once and keeping a running answer is the backbone of linear-time solutions.