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 cant pass this stage

squaring.py

Steven Parker
Steven Parker
231,275 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

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.