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

Stuck on Challenge task 2 of 2 - Putting the "Fun" Back in "Function"

Hi all,

Think I may be over complicating this, but I can't get past this code challenge.

If I run the code in Python outside workspaces, it works fine, but fails when trying to complete the challenge.

Here's my code...

def add_list(my_values):
    total = sum(my_values)
    print("Total: {}".format(total))
    return total

def summarize(my_values):
    total = sum(my_values)
    msg = "".join(str(x) for x in my_values)
    print("The sum of {} is {}.".format(msg, total))

my_values = [1,2,3]
add_list(my_values)
summarize(my_values)

Any pointers appreciated! :smile:

2 Answers

Joseph Kato
Joseph Kato
35,340 Points

Your add_list function looks okay (although the print statement is extraneous).

However, there appears to be two issues with your summarize function:

  1. You're not actually returning a value, which is what the challenge requested.

  2. Your msg variable is a string consisting of the individual elements of my_values, but the challenge asked for a string version of the list itself -- i.e. "[1, 2, 3]".

Thanks Joseph.

I think I was looking at it for too long and lost the plot.

Your comments have made perfect sense so I'll have another go at this tomorrow.

Thanks for the reply. :smile: