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

how do i get the result now

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 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!!!

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 68,454 Points

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

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 68,454 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!!!