Welcome to the Treehouse Community
Looking to learn something new?
Why won't this work?
def squared(num1): try: int(num1) return num1 * num1 except: return num1 * len(num1)
- >>> squared(2)
- >>> squared(5)
- >>> squared("tim")
Look's like it works fine to me...What gives?
This is what frustrates me the most about TreeHouse's test environment. I waste a lot of time where my code works fine when I test it out but their test environment is so obtuse as it will only except one specific solution despite any other solutions that may also be working.
This problem is, I don't always know what "that" single solution is and end up wasting my time trying to to guess which the TreeHouse test environment wishes to see.
# EXAMPLES # squared(5) would return 25 # squared("2") would return 4 # squared("tim") would return "timtimtim"
Forget it. I did another trial an error to make the test environment happy.
It was retarded as it wanted the following as a pass:
def squared(num1): try: num1 = int(num1) * int(num1) except: return num1 * len(num1) return num1
Why it prefers it this way which is not the DRY method, who knows?...