Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping Create a Function

Nick Mitias
Nick Mitias
1,845 Points

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

Brandon White
seal-mask
MOD
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Treehouse Moderator

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.

Nick Mitias
Nick Mitias
1,845 Points

Thank You! This helps a lot!