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 trialRaimond Põldaru
470 PointsPutting the "Fun" Back in "Function". Still don't get it done.
Don't get what am I doing wrong here. I have watched video several times and don't see what should I do...
# 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.
list = ([1, 2, 3])
def add_list(list):
total = 0
for i in list:
total += i
return total
def summarize(list):
total = add_list(list)
return ("The sum of [1, 2, 3] is {}.".format(str(list), total + "."))
1 Answer
William Li
Courses Plus Student 26,868 PointsHi, Raimond Põldaru , I guess you are a bit caught up by what the example test code is saying.
summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
No, you shouldn't have handcoded [1, 2, 3]
into your return String, because imagine what if the argument pass to the summarize
function isn't [1, 2, 3]
, then your output String doesn't make sense. You should use String interpolation to do the job.
also, make use of the add_list
function you previously defined will make this problem easier.
def summarize(list):
return "The sum of {} is {}.".format(list, add_list(list))
A word of friendly advice. Don't use word like list
, sum
as function parameter name, as they shared the same name as Python's built-in functions. In some rare cases, doing so can cause conflict in your code that is very hard to debug.