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!

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

Daniel Semeck√Ĺ
Daniel Semeck√Ĺ
384 Points

Have trouble with creating a function

Hi, I am stuck on this question and could use some advice.

The question goes like this: Create a function named square. It should define a single parameter named number. In the body of the function, return the square of the value that was passed in.

Which I did easily as this

def square(number): return number * number

But then the second part goes like this

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.

I am really unsure about what to do and have tried many things, can somebody please explain? :/

In that quiz there is a hint box. it should give you the ruff answer.

Caleb Newell
Caleb Newell
12,562 Points

if that dosn't work, show me the code and i will help also .

1 Answer

When you call a function you are just telling the program to execute the function. You type the name of the function with any parameters in parentheses. For example calling

myfunction(a,b)

with a=2 and b=3 would be

myfunction(2,3)

If the function returns a value it can be assigned like a variable

result = myfunction(2,3)

Daniel Semeck√Ĺ
Daniel Semeck√Ĺ
384 Points

Thank you, now I understand.