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

Laknath Gunathilake
Laknath Gunathilake
1,860 Points

can't seem to pass this challenge

I'm not sure if I understand this question correctly, but I can't seem to pass the challenge

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

1 Answer

Gavin Ralston
Gavin Ralston
28,770 Points
def squared(you_need_to_set_a_parameter_here):
# squared(5) would return 25
  try:
    square = int(number)**2    ## check you're using two *'s and not just one, so you raise to a power instead of multiply
    return square
  except: 
    return number * # times the length of the number variable, which is NOT an integer

Also, be sure to check your indentation. Assigning square a value and returning square don't require additional indents.

You'll need to add the last bit yourself, but I commented what you need to do to pass.

Remember, he's asking you to square the value if it's an integer, otherwise you're doing that python thing, where you multiply the string or whatever by printing it x number of times. So if somebody passed it "aaa" you'd want to return "aaaaaaaaa"

Hope that helps a bit!

Laknath Gunathilake
Laknath Gunathilake
1,860 Points
<p>
def squared ():
  try:
      square=int(number)**2
      return square 
  except:
      return number*
</p>

It says  SyntaxError: return number*