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

Radha Bhambwani
Radha Bhambwani
10,182 Points

Possible bug in 2nd functions challenge

So I've written code for the TeamTH UI for the 2nd functions challenge in the Python Basics class, that says that the return my function returns is wrong. TeamTH says that it returns None instead of the desired solution of "The sum of [1,2,3] is 6". However when I test my code on my Mac's terminal, I get the desired solution. I have attached my code below as well as an attachment.

def add_list(list): sum=0 for each in list: sum = each+sum return sumdef add_list(list): sum=0 for each in list: sum = each+sum return sum

def summarize(list):

print("The sum of {} is {}.".format(list,numz))

list = [1,2,3] numz = add_list(list) summarize(list)

functions.py
# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.

def add_list(list):
  sum=0
  for each in list:
    sum = each+sum
  return sum

def summarize(list):
  print("The sum of {} is {}.".format(list,numz))

list = [1,2,3]
numz=add_list(list)
summarize(list)

1 Answer

Kevin Franks
Kevin Franks
12,933 Points

The summarize function is printing the string not returning it. Just change the print statement to return and you should be good to go.