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 trialGabrielHumbertoAvelino GomesArevalo
Python Development Techdegree Student 753 PointsIn the body of the function, return
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 that was passed in.
(A *square is the value multiplied by itself. eg: The square of 5 is 25. 25 = 5 x 5)*
hi, Im working in python and I manage to get the result in many different ways but the program doesn't accept my answer.
def square(number): return number ** 2
choose_number = 5 result = square(choose_number)
print("The double of", choose_number, " is ", result)
or
def square(number): return number ** 2
choose_number = int(input("pick a number: ")) result = square(choose_number)
print("The Square of", choose_number, " is ", result)
1 Answer
Steven Parker
231,269 PointsIt's not clear what course and lesson you are referring to. But I seem to recall a code challenge that asked you to write a function to square a number, and then to call that function and assign the value to a variable.
But if I'm remembering correctly, it did not ask for anything to be input or printed. It's important in challenges to do only what the instructions ask for to avoid confusing the checking mechanism.
If that's not the problem, please post a link to the course page you are working with (and fix the code formatting).
Steven Parker
231,269 PointsSteven Parker
231,269 PointsAlways use Markdown formatting to preserve posted code's appearance, particularly indentation which is crucial in Python.