Amos Baynes1,495 Points
I've tried a few variations on this problem, but I keep getting this error: TypeError: can't multiply sequence by non-in
I thought the except TypeError: was supposed to catch this error, but it's still throwing it.
# EXAMPLES # squared(5) would return 25 # squared("2") would return 4 # squared("tim") would return "timtimtim" def squared(num): try: int(num) except TypeError: return num * len(num) else: return num * num
Jennifer NordellTreehouse Moderator
Hi there! The type error is actually being produced from your
else clause. Remember, the
int method to convert to an integer can accept either a number or a string. You should be checking for a
try part, you have
int(num). Imagine for a minute that we send in "27" as a string. That is a string that can be converted to an integer, and thus neither the
TypeError nor the
ValueError will be triggered and it will hit the
else clause. At that point, you then try to multiply the string 27 by the string 27 which can't be done. This is where you're getting the
TypeError from. To fix this, in your try block you need to overwrite the current value of
num with the
num after it's converted to an integer. That way, when your else clause is hit, it will be an integer times an integer.
Hope this helps, but let me know if you're still stuck!