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 trialNicolas Villarreal
282 PointsI am not sure why I am getting the error: 'int' object is not callable based on my code.
I thought I passed the argument of 3 into my square function I created and set that equal to my new variable called result and I then return the answer. I am not sure why I am getting this error.
def square(number):
square = number*number
result = square(3)
return result
2 Answers
Steven Parker
231,248 PointsWhen you put parentheses after a name, it's normally to invoke the function of that name. But "square" is not a function here but an integer value created on the line before.
Extra hints:
- don't use the same names for functions and variables
- calling a function from inside itself (unconditionally) creates an "infinite loop"
Susan krystof
Courses Plus Student 2,662 PointsWhat you should do is return the square of the number that will be passed in, which is number * number, What you did is call the function square inside itself. You can't call a function inside itself
def square(number):
return number*number
OR
def square(number):
result = number*number
return result
Nicolas Villarreal
282 PointsYes I had that part down but I need to call my function and pass in the argument of 3. I should store this as the result variable
Steven Parker
231,248 PointsSure, but that task should be done after the function definition, not inside it.