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

Could someone please help explain what they think I am not understanding from this.

Please help explain what is wrong with the current code as well as how the 'working' code works.

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

def squared(var):
    var = 5
    try:
        return int(var) ** 2
    except var:
        return item * len(item)

1 Answer

Ioannis Leontiadis
Ioannis Leontiadis
9,828 Points

Hello Jessica,

first of all the argument called var is assigned a value of 5 inside the function so the function always return the value of 25. You should remove that assigning statement.

Also, the try-except statement should be revised. The basic syntax is,

try:
    #code here
except Error:
    #code here

You should use ValueError in the place of Error for this problem.

Hope that helped!