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 Returning Values

Really Stuck

I am really struggling to write the code required for the function challenge.

so far all I got was def square(number): return number * number square(3)

how do I then store the value returned in a new variable called result.

Thought I was doing ok, but I have hit a road block.

thanks

2 Answers

The wording on these can be confusing so I'll try and show you how I broke it down in my head:

"Under the function definition, call your new function and pass it the argument 3."

  • "call the function" means to type out the name of the function. "Pass the argument" is asking you to enter that number in the parenthesis
def square(number):
return number * number

square(3) # call the function, 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."

  • The first thing I see is they wants a new variable named "result" so that part is pretty straight forward:
result = # something will go here
  • Then it says "to store the value from the function call." When you called square(3) it technically holds the value of 9 (since 3*3 = 9). So ultimately they want you to create the variable named "result" to store the value of square(3).
def square(number):
return number * number

result = square(3) # call the function, pass it the argument 3, store this value in a new variable called "result"

I hope this helps!

Dom Ss
Dom Ss
4,338 Points

Perfect explanation @Christy Grimaud

variable = function(argument) # the variable will hold whatever the function returns

Hi. Thanks for the post. Im still struggling. My code so far is as below

def square(number):

return number * number

The next part to the question is below. What would you add to the code to complete this question? thanks

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.