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

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,064 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,064 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,064 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,064 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,064 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!