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

`squared` didn't return the right answer.

pls help i dont understand whats wrong with my code

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

1 Answer

Christian Mangeng
Christian Mangeng
15,970 Points

Hi Dmitry,

your code looks fine overall. These things need to be changed:

1) you don't need to write the type of parameter taken by the function (def squared(x) is sufficient)

2) the integer conversion check should work for all values x, so x = int(x)

3) you do not need to call the function

def squared(x):
    try:
        x = int(x)
    except ValueError:
        return x * len(x)
    return x * x