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 trialAbdallah El Kabbany
2,042 PointsI 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.
# 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
Alexander Davison
65,469 PointsFirstly, you are doing a good job! 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
23,733 PointsA 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.
Abdallah El Kabbany
2,042 Pointsthank you :)
Jennifer Nordell
Treehouse TeacherHere's another hint. There's not anything that's supposed to be printed. Everything is supposed to be returned per challenge specifications.
Abdallah El Kabbany
2,042 Pointsthank you so much :)
Abdallah El Kabbany
2,042 PointsAbdallah El Kabbany
2,042 Pointsthank you :)