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

i need for help with this Challenge :(

i don't know why this is the only last challenge and its doesn't work with me :/ can i have some help please thanks for all members

3 Answers

def add_list(list):
    sum = 0
    for x in range(len(list)):
        sum = sum + list[x]

    return sum
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

While this will work, why are you counting your way through the list?

for x in list:

Also, you probably don't want a variable named list since that'll override the list() type/function and prevent you from being able to make lists that way (it won't matter in the code challenges, but you'll definitely want to avoid it in your own code).

Kenneth Love, thanks for the feedback. Please suggest another way to count without counting my way through the list. Thank you

Kenneth Love
Kenneth Love
Treehouse Guest Teacher
def add_list(lst):
    sum = 0
    for item in lst:
        sum += item
    return sum

You very rarely have to count your way through a list (or any other iterable) in Python. You can just loop through the members of the list directly.

its doesn't work with me :(

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I just entered exactly the code in my above comment to H U and it passed the first step of the code challenge.