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!

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

Python Python Basics (Retired) Putting the "Fun" Back in "Function" Functions

Luke Telford
Luke Telford
2,931 Points

How 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

Hi 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
Luke Telford
2,931 Points

Thank you! this was a great help