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 Functions and Looping Create a Function

Harjan Anand
Harjan Anand
780 Points

how do i get the result now

squaring.py
def square(number):
    return number * number

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,464 Points

Hey Harjan Anand, task 2 asks you to call your function and create a new variable results to store the returned value in.

  • call a function by adding parens () after the function name. Any arguments are placing inside the parens. So calling square with the argument 3 would look like
square(3)
  • create a new variable is to put a name on the left side of the equals sign =, as in
results =

Putting them together stores the results of the function call in the names variable:

results = square(3)

Edit: to define and call a function would look like:

def func(num):
    return num * num

result = func(10)

where the call is not indented. The change in indentation indicates the function definition has ended and code outside of the function is being defined.

Post back if you need more help. Good luck!!!

Harjan Anand
Harjan Anand
780 Points

This is my code so far :

def square(number):
    return number * number

result = square(5)

But it keeps saying this :

AssertionError: 25 != 9 : Make sure you store the return value from the function in a variable named result

And I dont understand what I have to do now?

Chris Freeman
Chris Freeman
Treehouse Moderator 67,464 Points

Updated answer to show the form of the answer using similar code. (trying to avoiding posting cut-and-paste answer)

Harjan Anand
Harjan Anand
780 Points

ok now i even changed it what do i do now : and says this: AssertionError: unexpectedly None : Make sure you create a new variable named result

It looks like this :

def square(number):
    return number * number
    result = square(3)
Chris Freeman
Chris Freeman
Treehouse Moderator 67,464 Points

I see after formatting that the assignment to result is indented too far. As it is now it’s inside the function.

Post back if you need more help. Good luck!!!