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 trialAndrew K
13,774 Points2nd 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) + "."
Andrew K
13,774 PointsThank 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
35,340 PointsHi Andrew,
It looks like there are two issues:
You forgot a
+
between " is " andadd_list(x)
.add_list(x)
returns anint
, which cannot be directly concatenated with astring
.
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
13,774 PointsAh! Thank you, Joseph! That's perfect!
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherAs Joseph Kato mentioned below, you missed a
+
. This causes a general syntax error and that's why step 1 is no longer passing.