Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Number Game App Squared

Why is this simple bit of code wrong?

I'm not sure why this setup doesn't work. Any input?

squared.py
def squared(arg):
  try:
    return arg * arg
  except:
    return arg * len(arg)

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,987 Points

The challenge asks you to try converting the argument to an int before squaring. Wrap each arg in int()

Dan Garrison
Dan Garrison
22,445 Points

Here's a hint. The argument entered into the function can either be an integer or a string. In order to multiply a number together, it needs to be turned into an integer. So this is what you should try first. If it fails to turn the argument into an integer then that is where the exception statement will run.

Thanks!