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

Challenge lesson: Create a function named square. I dont get this can you guys please help me

I dont really understand any of it please someone break it down for me and explain what they want me to do.

squaring.py
import math

def square(number):
    return ("squared")

squared = (number * 2)

print(squared)

3 Answers

When you're trying to find the square of a number you have to multiply it by itself.

For example:

The square of 3 is 9.

3 x 3 = 9

I'll try to explain as a newbie in python myself.

Its telling you to : Create a function named square. It should define a single parameter named number.

So your line of code that reads: def square(number) Is correct.

So you use the : to open the body and you wrote returned(squared)

And then you wrote squared = (number *2)

I believe you are getting a error message with this code or a define error.

So What I did in the body is I returned the parameter number times itself.

Then I assigned result to square(3)

And you print the result.

I hope I helped you in some way because this was also a challenge for me too.

Dont give up !

The objective was to

  1. Create a function called square and
  2. define a single parameter named number.

In your code below, you used didn't call it number but squared.

Your code would work but wouldn't pass the exam, because we're expecting the argument named "number" instead of squared.

def square(squared):
    return(squared*squared)

print(square(5))