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 trialnoahkeef
640 PointsCould someone help with the Functions code challenge?
I am completely baffled by this code challenge. I don't know where to start. I barely understand how the for loops work, and I have forgotten how to add the values together. Could anyone give me advice on how to complete this code challenge?
1 Answer
Martin Cornejo Saavedra
18,132 PointsHere's the answer, please ask if you didn't understand something:
# 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(my_list):
total_sum = 0
size = len(my_list)
for number in range(size):
total_sum += my_list[number]
return total_sum
def summarize(other_list):
total_sum = add_list(other_list) #here we may use the function defined before
my_string = "The sum of {} is {}".format(other_list,total_sum)
return my_string
Jariel Arias
1,549 PointsJariel Arias
1,549 PointsHere's my answer: