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

Dmitry Vasyanin
Dmitry Vasyanin
746 Points

What promts the SyntaxError SyntaxError: except ValueError:

New here on treehouse and new to python Can't figure out the solution to this problem and dont understand why the SyntaxError pops up Help pls)

squared.py
def squared(x):
    try:
        x = int('six')
        except ValueError:
            return x * len(x)
    return x ** 2 

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

that error is from indentation: the try and except need to be at the same level of indentation, so move the except left to be even with try, and the body of except to be even with the body of the try. then, what you are int casting is the argument fed into the function, held by the parameter x. reassignment like you have is fine, just change the argument to int to the parameter instead of the string 'six'.

Dmitry Vasyanin
Dmitry Vasyanin
746 Points

Thx that helped but now it says : squared didn't return the right answer.