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

David Ton-Lai
David Ton-Lai
3,268 Points

I'm not sure why I can't continue, this code works in my text editor.

I'm not sure why I can't continue, this code works in my text editor.

squared.py
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"
def squared(number):
    try:
        number = int(number)
        result = (number * number)
        print(result)
    except ValueError:
        result = (number * len(number))
        print(result)

1 Answer

Mike Hickman
Mike Hickman
19,817 Points

Hi David,

In the challenge it wants you to return the result instead of print it. This mix up happens a lot, so don't worry about it. Just know there is a difference. I don't know python syntax, but try replacing both of your prints with return instead.

Good luck,

Mike

David Ton-Lai
David Ton-Lai
3,268 Points

Wow of course, thanks so much Mike! Sorry to bother you with such a stupid question, I just need to be more careful.