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!
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
Omprakash Panigrahi9,632 Points
Code works on system but not on the quiz site
The code returns the correct results when run on a python compiler in the pc but it doesnt work when i try to submit my code.
# EXAMPLES # squared(5) would return 25 # squared("2") would return 4 # squared("tim") would return "timtimtim" def squared(item): try: return int(item ** 2) except: length = len(item) return item*length
I just tried this in the try block and it worked for me: return (int(item) ** 2)
Because you first need to turn the item into an int if you are going to be able to square it.
If you leave it like this: return int(item ** 2)
it will do whatever is inside of the parentheses first. Which could mean trying to square a string, which would not work