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

Artjom Dzug
Artjom Dzug
8,238 Points

i dont understand

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.

What is the problem?

squaring.py
def square(number):
    number = int(5)
    result = number * number
    return result

it's actually much simpler than that

create a function named square. it should be defined as the number

def square (number):

inside square return the math that is square

return = number*number

because square is (in math ) x times x, but our x in the code is NUMBER so that's why its (number*number)

final code would be:: def square(number): return=number*number

4 Answers

Artjom Dzug
Artjom Dzug
8,238 Points
def square(number):
  result = number * number
  return result
square(5)

Thank you Artjom

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

It looks like you're trying to define the value of number at the same time as making a calculation of result in the function.

You don't need to define number in your function as you're passing in number as a parameter. So delete it from inside the function so all you have is the result variable.

Then, all you do is call the square function below the function definition.

like this

square(5)

I still don't understand

def square (number):
    return number ** 2

def square(number): return ((number) * (number)) print("The square of", square)

this is also work