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

Sergej Dolezil
Sergej Dolezil
958 Points

Worked in workspace..

Hi,

I tried my code and variations of it in workspace and all of them work (adding an else: clause, using two lines instead of one for converting num to int and then returning the square...

I'm stuck...

thanks in advance!

squared.py
# 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:
        return(num * 2)

1 Answer

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

Hi there! You're doing really well here, but the problem lies in what you're returning in the except clause. You're returning the argument times 2. And that would be fine if the argument is "hi", "oh", or "no". Because those all have a length of 2. But what they want is for you to return the argument times the length of the argument. Let's take your name "Sergej" for example. It should print out Sergej 6 stimes because it has a length of 6.

I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

Sergej Dolezil
Sergej Dolezil
958 Points

Hi Jennifer,

I literally just saw my mistake, added the len function and closed the challenge, and was about to delete the question.

Thats what I get for not reading carefully to the end of the task :)

thanks again