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 trialThe Hacker
20,260 PointsSome body knows what I'm doing wrong?
total =0
def add_list(items = [] ):
total = 0
for item in items:
total += item
print("The total is {} ".format(total))
def summarize(list_1 = []):
total = 0
for item in list_1:
total += item
print("The sum of {} is {}.".format(list_1,total))
1 Answer
Chris Shaw
26,676 PointsHi Pedro,
Your code in general is valid but in the context of the challenge has an issue, you're printing strings from within your functions instead of returning them which is standard behaviour for functions. See the below which I've reformatted and cleaned up.
def add_list(items):
total = 0
for item in items:
total += item
return total
def summarize(list_1):
total = 0
for item in list_1:
total += item
return "The sum of {} is {}.".format(list_1, total)
Happy coding!
The Hacker
20,260 PointsThe Hacker
20,260 PointsOhhhhh thanks a lot. I hate doing silly coding jaja
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou could also make use of the
add_list
function insidesummarize
so that you don't have to figure out the total again.