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 trialHarjan Anand
780 Pointshow do i get the result now
def square(number):
return number * number
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsHey 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 argument3
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!!!
Harjan Anand
780 PointsHarjan Anand
780 PointsThis is my code so far :
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
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsUpdated answer to show the form of the answer using similar code. (trying to avoiding posting cut-and-paste answer)
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsThe challenge asks for argument 3 not argument 5.
Harjan Anand
780 PointsHarjan Anand
780 Pointsok 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 :
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsWhatβs the latest version look like?
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsI 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!!!