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 trialRusell Shamu
4,592 PointsCreating 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.
def square(number):
return number * number
2 Answers
Alexander Davison
65,469 PointsThe 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)
Dirga Gurung
2,730 Pointsresult = (square(3))
James Rennie
16,807 PointsWhy did you add extra brackets to the previous comment?
James Rennie
16,807 PointsJames Rennie
16,807 PointsThanks could not figure out how to get return total into var named result.