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

Maor Beeri
Maor Beeri
2,154 Points

got a problem

I get this message error and don't know what to do :( need someone's assistance

squared.py
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared (x):
    try:
       num = int(x)
    except ValueError:
        return num * len(num)
    else:
        return num*num

2 Answers

Steven Parker
Steven Parker
216,136 Points

You're very close! But when the exception occurs, the variable "num" does not get assigned. So the code in the exception block should work with argument "x" directly instead.

Maor Beeri
Maor Beeri
2,154 Points

oh now I understand thanks a lot!

Dave StSomeWhere
Dave StSomeWhere
19,822 Points

Double check what you are doing to handle the exception and pay attention to the bummer error message, it is telling you the issue.