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 trialSCLAUDINA VARGAS
Courses Plus Student 308 Pointsfunction
Why is the following code wrong?
def add_list(list_x): sum(list_x)
When I try it in the shell it works fine; however, it appears to be wrong answer in the quiz.
# 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_x):
sum(list_x)
3 Answers
Seth Reece
32,867 PointsYou could also do it the long way as the challenge suggests:
def add_list(list):
i = 0
for item in list:
i = i + item
return i
Seth Reece
32,867 PointsHi Sclaudina,
Your function needs to return something when it is called. e.g.
function add_list(list):
return sum(list)
Kenneth Love
Treehouse Guest TeacherI think you mean def
instead of function
. Been doing JavaScript lately?
SCLAUDINA VARGAS
Courses Plus Student 308 PointsI tried as you indicates and also using print() like: def add_list(list_x): print(sum(list_x)) In both cases the answer to the quiz appears to be wrong. However, it works fine offline.
Thanks a lot for your kindness.