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

NameError on my function. I can't understand how this is "not "defined". Haven't I just defined it as my function?

I have been stuck on the second part of this for days! How am I to further define my summarize function? It took my add_list function ...

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Can you post your code?

From the docs

exception NameError

    Raised when a local or global name is not found. This applies only
    to unqualified names. The associated value is an error message
    that includes the name that could not be found.

I'm just a mess, I guess. I was sure I had the attach code box checked. I don't know how to add it now.

That's what I tried to do! I cannot believe I can't even cut and paste right now!!! Thanks for your patience. I will figure out what's going on.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Weird, I saw your code in a comment, then it disappeared. Here's what I captured:

num_list = []
def add_list(num_list):
  for item in num_list:
    total = sum(num_list)
  return total
def summarize(num_list):
  return "The sum of {} is {}.".format( str(num_list), sum(num_list))

[MOD: added ```python markdown formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

When I run your code, it passes as written in the challenge.

That is weird. You got what I've tried. It seems logical to me. I wonder why it isn't passing the challenge. Thank you so much for your time! :)

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

So it's still not passing or you're wondering why it didn't but now does?

There have been some glitches in the challenge grading, where the correct code failed, but passes a short time later.

Still not passing challenge. The first part passes and the I get "NameError: "summarize" not defined for the second

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

check the indentation. the def add_list and def summarize must both start in column 1. Also try adding a blank line between the functions for clarity (shouldn't matter syntactically).

Thank you thank you thank you!!! It worked when I adjusted the indentation!