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

Didier Borel
Didier Borel
2,837 Points

square of a number

i am not quite sure what I am doing wrong here

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

6 Answers

Idan Melamed
Idan Melamed
16,285 Points

Hi Didier,

A few things.

  1. You don't need an input from the user. Assume the user will call the function with an argument like this "squared(5)"
  2. Inside "try:" you should try to return (the int value of the argument) ** 2
  3. If there is an error, return the argument * len(argument)

Try it a few times, and if you are still stuck I'll post my answer, ok?

Idan Melamed
Idan Melamed
16,285 Points

I found a simpler way... So I changed the steps above.

Idan Melamed
Idan Melamed
16,285 Points

Did you manage to find the answer?

Didier Borel
Didier Borel
2,837 Points

i have to catch a plane now, I probably won't be able to come back to this until next week, but thxs anyway.

Alex, your solution returns
"squared didn't return the right answer"