Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (Retired) Putting the "Fun" Back in "Function" Functions

YI LI
YI LI
4,094 Points

challenge task 2 of 2

I run the task 2 on workspace successfully. But the challenge always give me an error.. Can somebody help me? Thank you.

functions.py
# 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(arr):
  total = 0
  for a in arr:
    total += a
  return total

def summarize(aList):
  print("The sum of {} is {}".format(aList, add_list(aList)))

summarize([5,2,6])

2 Answers

hie there.

you should return that string and not print it, just replace your print with return and it will work out fine. the syntax is correct that's why it runs on workspaces but it wont pass the challenge because the challenge is hard coded to accept return as stated in the task.

don't forget to remove the extra pair of parenthesis(outer braackets) when you remove print.

YI LI
YI LI
4,094 Points

Thank you very much!!!

am glad I could help, don't forget to upvote