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

Creating a function

I am stuck on this task. This is exactly how the task is asked below:

Great now that you have created your new square method, let's put it to use. Under the function definition, call your new function and pass it the argument 3. Since your square function returns a value, create a new variable named result to store the value from the function call.

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

2 Answers

The challenge first stated "Under the function definition, call your new function and pass it the argument 3." Remember that to call a function, you specify the function name, followed by a set of parentheses, and in-between the parens the arguments provided. So, to call the square function and pass it the argument 3, you do square(3).

The challenge then said to "create a new variable named result to store the value from the function call." Defining a variable is easy; you specify the variable name on the left, followed by an equal sign, followed by the value. In this case, the value is the returned value of square(3).

Thus, you see this after writing down the code:

result = square(3)

Thanks could not figure out how to get return total into var named result.

Dirga Gurung
Dirga Gurung
2,730 Points

result = (square(3))

Why did you add extra brackets to the previous comment?