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

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 47,480 Points

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