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

Now, make a function named summarize that also takes a list. It should return the string "The sum of X is Y.", replacing

i keep getting a oops task 1 is no longer passing

functions.py
def add_list(lst) :
  result = 5
  for item in lst:
    result += item
    return result

  def summarize (another_list) :
    sum = 0 
    for number in another_list):
      sum = number + sum 
      return "The sum of {} is {}".format(str(another_list), sum)

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

From the Putting the Fun Back in Function Challenge Functions

The error "oops task 1 is no longer passing" usually indicates that a syntax error as been introduced. This causes all tests to fail, and hence, task 1 to stop working.

It looks like summarize() needs to be outdented to be at the same level as add_list()

Also, there is an extra paren ")" , and the return statement should not be inside the for loop. Remove one indent from your return result line from your summarize() function. Also, your add_list() function return statement is also intended too far.

  def summarize (another_list) :
    sum = 0 
    for number in another_list): # <--- REMOVE extra paren
      sum = number + sum 
      return "The sum of {} is {}".format(str(another_list), sum)  # <--- this is indented too far

By "outdent" I mean one indention level needs to be remove from every line in the summarize() function. All together it would look like:

def add_list(lst) :
  result = 0  # <-- Changed starting count to 0
  for item in lst:
    result += item
  return result  # Fixed Indent

# Fixed indent of entire function
def summarize (another_list) :
  sum = 0 
  for number in another_list: # <--- Removed extra paren
    sum = number + sum 
  return "The sum of {} is {}".format(str(another_list), sum) # Fixed Indent

Acknowledging Sam Matrouh for suggestion the challenge objective of using add_list in the summarize function

def summarize (another_list) :
  return "The sum of {} is {}".format(another_list, add_list(another_list))
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Also, the str() isn't needed in the format statement. format() takes care of that for you!

Sam Matrouh
Sam Matrouh
14,694 Points

For anyone who might stumble on this in the future. You can use the function you created earlier instead of recreating the loop in the summarize function.

chris freemen can you show me what you mean please

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I updated my answer above. There were a few more indention issues to fix. Keep at it! You'll get it!

that didnt work

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

alec burnett, you're correct. There was a hold over from the original post. Result needed to be initialized to zero. I've corrected my answer above.