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 trialLuke Telford
2,931 PointsHow to use for loop?
I can't wrap my head around this, in the challenge it says to sue a for loop to run both these functions but i don't remember anything being said about for loops during this course. How do I go about doing this?
1 Answer
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Luke
this is how you want to do it.
def add_list(mylist):
total = 0
for num in mylist:
total = total + num
return total
You pass a list to the function for example my_list = [1,2,3] which should return 6 when the function add_list() is called.
Luke Telford
2,931 PointsLuke Telford
2,931 PointsThank you! this was a great help