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!

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

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.