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
Elnur Ibrahim-zade
24,141 PointsPython Functions Challange task 2 of 2
Hi, whats wrong with this code?
def square(number): number=number**2 return number result= int(square(5)) print (result)
1 Answer
Eric M
11,547 PointsHi Elnur,
Depending on what you're trying to do your code could be fine.
It could be formatted better though, let's assume your code looks like this:
def square(number):
number = number ** 2
return number
result = int(square(5))
print(result)
When run this will print 25, and the square function works as you would expect (it returns the square of the number it was passed).
If you are trying to pass the coding challenge here: https://teamtreehouse.com/library/python-basics-3/functions-and-looping/create-a-function, there are a few things that will trip you up. The coding challenge is not expecting you to cast the result from square() to int and this can actually prevent you from passing, same with the print statement. It's also wanting you to square the number 3 instead of 5. Just replace those two lines with result = square(3).
If you're working on a different problem just let us know what you're trying to do.
Cheers,
Eric
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsCan you link to the challenge?