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 trialEric Goya
Courses Plus Student 1,124 PointsPractice functions. Bad return
I made this code:
_list = [] def add_list(num): _list.append(num) return(sum(num))
def summarize(num):
return ("The sum of {} is {}.".format(_list,(sum(num))))
and the return is like this : The sum of [[1,2,3]] is 6.
How do I fixed to get only [1,2,3]
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return
# Note: both functions will only take *one* argument each.
_list = []
def add_list(num):
_list.append(num)
return(sum(num))
def summarize(num):
return ("The sum of {} is {}.".format(_list,(sum(num))))
1 Answer
Iain Diamond
29,379 PointsHi Eric, The only change required is in function summarize(), such that it prints out the input parameter, num, as shown below.
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return
# Note: both functions will only take *one* argument each.
_list = []
def add_list(num):
_list.append(num)
return(sum(num))
def summarize(num):
return ("The sum of {} is {}.".format(num,(sum(num))))
print(add_list([1,2,3]))
print(summarize([1,2,3]))
Hope this helps, iain