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

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

Make a function named add_list that takes a list.The function should then add all of the items in the list together.

Where am i getting it wrong please please assist

functions.py
def add_list(items_list):
  total = 0
  for item in items_list:
    total = total + item
    return total

3 Answers

Chase Marchione
Chase Marchione
155,055 Points

Hi Chipo,

It's an indentation issue (since Python is whitespace sensitive, code will not compile unless it is indented the amount that the compiler expects.) If you line the return statement up with the for loop declaration, your code will pass.

def add_list(items_list):
  total = 0
  for item in items_list:
    total = total + item
  return total

Hope this helps!

Hie CJ Thank you soo much you are a life saver.

sidni ahmed
sidni ahmed
3,329 Points

can someone please explain this. I don't get it. It says in the task it should return 6. Is this code returning 6?