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 trial

Python Python Basics Functions and Looping Create a Function

how do you Create a function named square. It should define a single parameter named number.

squaring.py
def square(number):

1 Answer

Steven Parker
Steven Parker
231,269 Points

You're good so far, but that's only half of the instructions. The rest say "In the body of the function, return the square of the value that was passed in."

So now add your function body beneath the declaration line to complete the challenge.

MightyIronElf 15
MightyIronElf 15
1,880 Points

But how do I add the rest of the function body? After typing my answer: number = (5) def square(number): return number *5 It keeps telling me my math is wrong and I have no idea what is wrong.

Steven Parker
Steven Parker
231,269 Points

A function body is created by adding one or more lines following the "def" line that are all indented. These lines should contain the code you want the function to perform. For the function to have a value the last line of the body should be a "return" statement.

You will also want the function to be able to work with any given number, so be sure not to use any constant values in the function code.

You might want to take another look at the code examples in the Functions and Returning Values videos.