Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Number Game App Squared

Emmett Armstrong
Emmett Armstrong
3,794 Points

int(num)?

This challenge is not giving me useful error messages. It simply says "try again", without telling me anything about what is wrong or how to fix it.

squared.py
# EXAMPLES
# squared(5) would return 25
# squared("2") would return 4
# squared("tim") would return "timtimtim"

def squared(num):
    try int(num):
        return int(num) ** 2
    except TypeError:
        return num * len(num)
Julio Garcia
Julio Garcia
1,944 Points

You have 2 Errors: 1.- You don't need to pass anything to the try exception. Remove the int(num) from try 2.- In the except call is not looking for a TypeError is looking for a ValueError.

Change that two error and check it again.

I fully agree with you on the try again errors. they just don't help. anyway your return for the except isn't right as the objective is asking for you to return a string. can you multiply a string to a number and get a output of string+string+string? i haven't tried to be honest.

1 Answer

Emmett Armstrong
Emmett Armstrong
3,794 Points

Thank you! I ended up finding my errors by dropping my code into Workspaces and running in the terminal.