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 trialSimon Whitwick
Courses Plus Student 199 PointsReally 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
Christy Grimaud
19,727 PointsThe 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!
Pedro Cabral
33,586 Pointsvariable = function(argument) # the variable will hold whatever the function returns
Simon Whitwick
Courses Plus Student 199 PointsHi. 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.
Dom Ss
4,339 PointsDom Ss
4,339 PointsPerfect explanation @Christy Grimaud