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 have a problem with a coding task

I am lost here i tried everything to get my code to work.

Create a function named square. It should define a single parameter named number. n the body of the function return the square of the value passed in.

Can anyone help?

squaring.py
import math

def square(number):
    return (number * number)
number = int(input("What number?  "))
total = square(number)
print(number)

So from what I can tell the challenge is only asking for a function not any input from a user, I think that if you get rid of all the lines of code past the return line it will work. I got the first task to pass with:

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

And the second part of the challenge still is not asking for a user input, it wants you to call the function using the number 3 and store the return in a new variable

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

result = square(3)

1 Answer

Steven Parker
Steven Parker
229,644 Points

You only need the argument passed in, and you will "return" the result. You don't need to "input" or "print" anything.

You also only need to define the function, the challenge validator will call it so you don't need to.