Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Zachary Wheeler
1,157 PointsHow to return sum of all values in a list
Exercise: sumlist
Description
In this exercise you will add up the values of all items of a list, and return the total.
Function Name
sumlist
Parameters
nums : a list of integers Return Value
The sum of all values in the list.
Examples
values = [ 1, 1, 2, 3, 5, 8 ] sumlist(values) -> 20 values = [ 2, 3, 5, 7, 11, 13 ] sumlist(values) -> 41
1 Answer
jacinator
11,936 Pointsdef sumlist(nums):
total = 0
for num in nums:
total += num
return total