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 Python Basics (2015) Number Game App Squared

def squared(arg): try: return int(arg)**2 except: return arg*2 it work on my computer

squared.py falied

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

oh, i didn't read the specs correctly it required to multiply in case of string by it's length :)

1 Answer

Ismail KOÇ
Ismail KOÇ
1,748 Points

Hi ahmed, if argument's data type is integer, function will return squared argument, else (except ValueError: ) function return multiple argument with length of argument argument (for ex: squared('aa') -----> return len('aa')*'aa' -----> aaaa)

Ismail KOÇ
Ismail KOÇ
1,748 Points

If you need help, do not hesitate ask me.