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 trialoussama
6,484 Pointsi 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
harishupadhyayula
32,221 Pointsdef add_list(list):
sum = 0
for x in range(len(list)):
sum = sum + list[x]
return sum
harishupadhyayula
32,221 PointsKenneth Love, thanks for the feedback. Please suggest another way to count without counting my way through the list. Thank you
Kenneth Love
Treehouse Guest Teacherdef 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.
oussama
6,484 Pointsits doesn't work with me :(
Kenneth Love
Treehouse Guest TeacherI just entered exactly the code in my above comment to H U and it passed the first step of the code challenge.
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherWhile 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 thelist()
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).