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

Corey Chattin
Corey Chattin
777 Points

More Python problems!

No idea why the code below will not work for the challenge I am on?

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

2 Answers

Gavin Ralston
Gavin Ralston
28,770 Points

Remove those print statements, just assign the values directly to num_to_str and sum_of_list and you'll be fine, I think.

def summarize(list_of_numbers):
  counter = 0
  for item in list_of_numbers:
    counter = counter + item
  num_to_str = str(list_of_numbers)  ## Now you're assigning the value to the variable
  sum_of_list = str(counter)               ## instead of printing it!
  return "The sum of {} is {}.".format(num_to_str, sum_of_list) 

Also be sure to enclose the return statement in the right number of parentheses. Remove the leading ( or add one at the end of the return statement (it isn't necessary)

That should give your return statement the right values.

Corey Chattin
Corey Chattin
777 Points

Thank you Gavin, I passed with the aid of your guidance!