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

Pls help to figure out how to defined 'arg' to make my script work

Pls help to figure out how to defined 'arg' to make my script work

squared.py
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4

def squared(arg):

    while True:
        try:
          arg = int()
          print(arg**2)
          return
        except ValueError:
          print(arg* len(arg))
          return
squared(arg)

2 Answers

Steven Parker
Steven Parker
230,248 Points

Here's a few hints:

  • just define your function, don't call it yourself (the challenge does that for you)
  • you don't need a loop (because of the return's, it can't loop anyway)
  • you need to pass an argument to int that you want it to convert
  • you need to return the values, not print them

I'll bet you can get it now, but if you're still stuck...     <button' onclick='$("#spoiler").slideDown("slow");$(this).remove()'>Press to Reveal Spoiler</button> <div id='spoiler' style='display:none'>

:warning: SPOILER ALERT

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

</div>

Thanks so much for the explanation! Now I see...