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

what's wrong about my answers in the functions task 2 of 2?

dont know what's wrong

functions.py
arr = [1, 2, 3]
def add_list(arr):
  total = 0
  for item in arr:
    total += item
  return total

def summarize(arr):
  list = str(arr)
  total = 0
  for item in arr:
    total = total + item

  # Remove the spaces at the start and end of your string.
  # Replace sum with arr, sum and total are the same.
  return " The sum of {} is {}. ".format(arr,total) 

3 Answers

rydavim
rydavim
18,814 Points

You still need to remove the spaces at the start and end of your string.

return " The sum of {} is {}. ".format(arr,total) # This one won't work to pass the challenge.
return "The sum of {} is {}.".format(arr,total) # This one should work to pass the challenge.

The automated testing that the challenges do to check your solution is pretty specific. So it just needs the string to not have any extra white space at the beginning or end. You've nearly got it!

Thanks , my bad , i didn't notice the "# Remove the spaces at the start and end of your string." part

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points

'''python <p># summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."

Note: both functions will only take one argument each.

arr = [1, 2, 3] def add_list(arr): total = 0 for item in arr: total += item return total

def summarize(arr): #use the function you created before #that's the whole point of this tutorial total = add_list(arr)

#no spaces at begging and end!!, you had "  The sum ...  " , correct is "The sum ..."
return "The sum of {} is {}.".format(str(arr),total) 

</p> '''

Martin Cornejo Saavedra
Martin Cornejo Saavedra
18,132 Points
<p>
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.
arr = [1, 2, 3]
def add_list(arr):
  total = 0
  for item in arr:
    total += item
  return total

def summarize(arr):
    #use the function you created before
    #that's the whole point of this tutorial
    total = add_list(arr)

    #no spaces at begging and end!!, you had "  The sum ...  " , correct is "The sum ..."
    return "The sum of {} is {}.".format(str(arr),total) </p>

thank you!

I am checking both your answers and try to get the differences