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 trialPetko Delchev
Courses Plus Student 2,103 PointsNeed help with squared function.
This is what I did:
def squared(num): try: return int(num) **2 except ValueError: return num * len(num)
def squared(5) def squared("2") def squared("Tim")
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(num):
try:
return int(num) **2
except ValueError:
return num * len(num)
def squared(5)
def squared("2")
def squared("tim")
1 Answer
Stuart Wright
41,120 PointsIf you delete the last three lines, your code passes. The challenge only wants you to define the function, not call it with any parameters.
As an aside, if you do want to call the function, you do not use the keyword def - that is only for the definition. To call it you would simply do:
squared(5)
Petko Delchev
Courses Plus Student 2,103 PointsPetko Delchev
Courses Plus Student 2,103 PointsThank you for the answer Stuart !