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 trialHamzah Iqbal
Courses Plus Student 2,529 PointsNot sure with this one.
Hey guys, so i know that the code is not done fully. However i'm trying to make the code myself as much as possible such that i learn from it. Which is why i didn't look anywhere for any answers. Can anyone guide me, towards what i should do ? Without giving any answers.
APPRECIATED!!!!
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.
def add_list(list):
for items in add_list:
return items + items
break
5 Answers
michaelangelo owildeberry
18,173 Pointswhat happens after you erase break and run code? =)
David Leacock
8,532 PointsYou need to use the += operator.
Hamzah Iqbal
Courses Plus Student 2,529 PointsThanks for the response David.
Like this? def add_list(list): for items in add_list: return items += items break
David Leacock
8,532 PointsI was thinking more like...
def add_list(list): temp = 0 for items in add_list: temp += items return temp
Hamzah Iqbal
Courses Plus Student 2,529 Points2 questions. First of all, why the temp = 0? Like what is your idea of doing all of this.
def add_list(list):
for items in add_list
temp = 0 for items in add_list:
temp += items
return temp
it still tells me Bummer! SyntaxError: for items in add_list
Kenneth Love
Treehouse Guest TeacherYou don't need break
at all.
Hamzah Iqbal
Courses Plus Student 2,529 PointsHey Kenneth.
Alright,however it keeps telling me
Bummer! SyntaxError: for items in add_list
Is that due to the way i have structured it (with the tabs/spaces etc)?
Kenneth Love
Treehouse Guest TeacherWell, add_list
is your function, not the argument passed to the function, so you want for item in list:
(really, use a better name than list
since list()
is a builtin function). You also need to make sure everything is indented inside your function. What you have in the first post isn't indented.
Hamzah Iqbal
Courses Plus Student 2,529 PointsHamzah Iqbal
Courses Plus Student 2,529 PointsHey man thanks for responding. When i remove it, it starts saying Bummer! IndentationError: for items in add_list: