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 trialMUZ140611 Audacious Jaunda
2,815 PointsI am stuck on Functions Code Challenge
after completion of my task 2 my task one then fails.
# 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.
list1=[1,2,3]
def add_list(list1):
sum_of_list=0
for num in list1:
sum_of_list = sum_of_list + num
return sum_of_list
def summarize(list1):
sum_of_list=0
for num in list1:
sum_of_list = sum_of_list + num
return "The sum of {} is {}.".format(str(list1),str(sum_of_list)
2 Answers
Michael Norman
Courses Plus Student 9,399 PointsYour white space is off in the summarize function as well as missing a parenthesis.
def summarize(list1):
sum_of_list=0 # one too many spaces here
for num in list1:
sum_of_list = sum_of_list + num
return "The sum of {} is {}.".format(str(list1),str(sum_of_list) # missing a parenthesis to close format()
MUZ140611 Audacious Jaunda
2,815 PointsThank you very much Michael. Much appreciated.