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 trialArtjom Dzug
8,238 Pointsi dont understand
Create a function named square. It should define a single parameter named number.
In the body of the function return the square of the value passed in.
What is the problem?
def square(number):
number = int(5)
result = number * number
return result
4 Answers
Artjom Dzug
8,238 Pointsdef square(number):
result = number * number
return result
square(5)
Ted Musgrove
4,400 PointsThank you Artjom
Jonathan Grieve
Treehouse Moderator 91,253 PointsIt looks like you're trying to define the value of number at the same time as making a calculation of result
in the function.
You don't need to define number
in your function as you're passing in number as a parameter. So delete it from inside the function so all you have is the result variable.
Then, all you do is call the square
function below the function definition.
like this
square(5)
Artjom Dzug
8,238 PointsThank you it worked
Ted Musgrove
4,400 PointsI still don't understand
Brad Thurlow
7,809 Pointsdef square (number):
return number ** 2
Sandeep Jaiswal
466 Pointsdef square(number): return ((number) * (number)) print("The square of", square)
this is also work
anthony pizarro
1,983 Pointsanthony pizarro
1,983 Pointsit's actually much simpler than that
create a function named square. it should be defined as the number
def square (number):
inside square return the math that is square
return = number*number
because square is (in math ) x times x, but our x in the code is NUMBER so that's why its (number*number)
final code would be:: def square(number): return=number*number