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 Function Code Challenge

I have been able to get past part 1 of this code challenge where I create the function add_list() which returns the summation of all of the numbers in the list.

I am stuck though on the part 2 where it wants you to return a string of the list and then the summation of the list which is found when using the add_list() function. The error keeps telling me that it is "expecting str" but is finding an int. I may not be using the .join() function correctly so the compiler keeps finding integers rather than strings. Any feedback would be great, thanks.

def add_list(list): new_item= 0 for i in list: new_item += i return new_item

def summarize(list): string_list= ' , '.join(list) list_form= list.split() return("The sum of ["+ string_list + "] is "+add_list(list_form))

1 Answer

Hi Patrick,

In your solution you are trying to join a list of integers which won't work. You should use the format function which will print out the list for you, without the need for joins or conversions.

Awesome! Thanks Jan, I'll try that out.