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

i cant pass this stage

squaring.py

Steven Parker
Steven Parker
216,012 Points

Please at least give it your best "good faith" try and then show your code. We can make suggestions from there to help you resolve any issues.

1 Answer

Jassim Alhatem
Jassim Alhatem
20,859 Points

Hi mate, maybe next time try to add in the question to the challenge or some code. Anyways, I'm gonna try to help you with both parts of the challenge.

So it wants you to create a function named square, let's do that

def square():

Then it said that it should define a single parameter named number.

def square(number):

Alright, it's pretty simple so far, now it wants us to return the square of number. To be honest with you, I hate squaring a number this way, but the challenge won't accept any other way, anyhow, I'm gonna show you both ways.

So the challenge wants you to do it this way.

def square(number):
    return number*number

I prefer using the module math to the way I showed above. you don't have to use the module, but it's cleaner.

This is the way I prefer.

import math

def square(number):
    return math.pow(number, 2)

Now to the 2nd challenge. Firstly, it wants you to call your new function and pass it the argument 3.

Ok, let's do that.

def square(number):
    return number*number
square(3)

But since your square function returns a value, it wants you to create a new variable named result to store the value from the function call.

Alrighty, let's do that.

def square(number):
    return number*number
result = square(3)

I hope you understood everything. If you need anymore clarifications don't hesitate to ask.