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 trial

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

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.

# 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)))


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.

4,094 Points

Thank you very much!!!

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