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

Andrew K
Andrew K
13,774 Points

2nd Step in Putting Fun Back in Function Code Challenge: What am I doing wrong?

The first step went down easily enough, but in my second step response, the quiz tells me that now the first function isn't working... What did I mess up in the second function?

def add_list(x):
  total = 0
  for item in x:
    total += item
  return total

def summarize(x):
  return "The sum of " + str(x) + " is " add_list(x) + "."
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

As Joseph Kato mentioned below, you missed a +. This causes a general syntax error and that's why step 1 is no longer passing.

Andrew K
Andrew K
13,774 Points

Thank you, Kenneth, it's nice to have the instructor checking in as well! I'm really enjoying the Python courses so far!

As it turns out, attempting to concatenate an int with a string had also been plaguing me for a while trying to crack this one, so thanks doubly to Joseph!

2 Answers

Joseph Kato
Joseph Kato
35,340 Points

Hi Andrew,

It looks like there are two issues:

  1. You forgot a + between " is " and add_list(x).

  2. add_list(x) returns an int, which cannot be directly concatenated with a string.

This should work:

return "The sum of " + str(x) + " is " + str(add_list(x)) + "."

That said, I'd do this:

return "The sum of {} is {}.".format(x, add_list(x))
Andrew K
Andrew K
13,774 Points

Ah! Thank you, Joseph! That's perfect!