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

Python

Squared coding challenge issues

So I'm having issues with the Squared coding challenge.

I have this piece of code, which works on my local machine, but not in the Treehouse environment. I get a: Bummer! squared didn't return the right answer, error message when I run it.

def squared(number):
      try:
          a = int(number)
          print(a * a)
      except:
          print(number * len(number))

And I know it looks like the indentation is off in this post, but it isn't within the Treehouse environment.

1 Answer

Error says: "I get a: Bummer! squared didn't return the right answer, ".

I would suggest to replace print with return statements.

def squared(number):
      try:
          a = int(number)
          return a * a
      except:
          return number * len(number)