Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,798 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