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

Greg Maddox
Greg Maddox
1,471 Points

This code works on my python shell, i'm not sure why its not working here

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

squared.py
def squared(count):
    try:
        numb = int(count)
        return (numb * numb)
    except ValueError:
        string = len(count)
        return (string * string)

2 Answers

andren
andren
28,558 Points

The instructions state that if the argument cannot be converted to an int then you should return the argument multiplied by its own length. In your code you return the argument's length multiplied by itself instead, which is incorrect.

If you fix that issue like this:

def squared(count):
    try:
        numb = int(count)
        return (numb * numb)
    except ValueError:
        string = len(count)
        return (count * string) # Changed string to count

Then your code will pass.

Greg Maddox
Greg Maddox
1,471 Points

Ah, thanks. That was very helpful.