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

Stepan Mytchyk
Stepan Mytchyk
2,669 Points

Why my code is not correct. I run it in the workspaces, and it's run well, but in "code challenge" it's return error.

My code is

def add_list(n): sum=0 for item in n: sum=sum+item return sum def summarize(n): print("The sum of {} is {}".format(str(n),str(add_list(n))))

2 Answers

Stone Preston
Stone Preston
42,016 Points

for the summarize function you need to return the string, not print it. you are also missing a period at the end of the string

def add_list(n):
  sum=0
  for item in n:
    sum=sum+item
  return sum

def summarize(n):
  return "The sum of {} is {}.".format(str(n),str(add_list(n)))
Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You'll likely never need to print() in a code challenge.