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

What am I doing wrong?

Can some one please help creating this function please?

squaring.py
def square("value * value")
    Vaule = 5 
    square("5 * 5 = 25")
    print("25")

1 Answer

A basic function looks like this:

def function(parameter):
    do something
    return value

The instructions for the challenge are: 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 passed in

So the function called square with a single parameter called number would be

def square(number):

From here it has to do something - in this case square parameter number

    value = number*number

So that value can be used outside the function you need the return statement

    return value

put together is

def square(number):
    value=number*number
    return value    

which can be shortened to

def square(number):
    return number*number