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

Abdallah El Kabbany
Abdallah El Kabbany
2,042 Points

I need help! please give me a feedback on what i did wrong

sometimes i confused when i go through challenges though i could have watched the videos twice minimum.

squared.py
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(num):

  while True:

    try:
      guess = int(input("give me an integer: "))

    except ValueError:
      print("{} is not an integer".format(num))

    if guess == int(guess):
      return(guess*guess)
    else:
      return(guess*len(guess))

3 Answers

Firstly, you are doing a good job! :smiley: However, you are overthinking. All you need is this:

 # EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"

def squared(num):
  try:
    return int(num) ** 2
  except ValueError:
    return num * len(num)
Kourosh Raeen
Kourosh Raeen
23,733 Points

A couple of suggestion to get you going. Remove the while loop and the input statement as they're not needed. Just work with the argument passed into the function, which you're calling num.

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Here's another hint. :bulb: There's not anything that's supposed to be printed. Everything is supposed to be returned per challenge specifications.