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

I am new to Python and I am stuck on a problem.

It says to define "square". How would I define it? Would I do "square = _"? What do I do? Please and Thank You,

squaring.py
def square(number):
    return number * square

2 Answers

Pretty close! It just needs to be:

return number * number

So if someone called square() with:

var1 = square(4)
print(var1)

The output would be: 16

Thank You!

Brandon White
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 Points

Hi Nick,

The challenge isn’t actually asking you to define square, but I think you’re probably getting an error that’s telling you that square is not defined. And so you’re thinking you need to define it, but in this case you do not.

What’s happening is that when the python interpreter reaches this line of code: return number * square, it’s saying, “I know what number is, it’s the value of the number that was passed into the function as an argument, but what is square? I don’t know what number that is, so I can’t do this math, so I’m just gonna let the user know that I can’t do it and exit the program.”

To get the square of a number, you multiply that number by itself. So your return statement should look like this: return number * number.

Do that and you should pass the first part of the challenge.

If you have any more questions, don’t hesitate to reach back out.

Good luck, Coder.

Thank You! This helps a lot!