it says num **2 or num * num why isn't it working?
So i think I have everything right but correct me if I am wrong. I don't understand why return(num ** 2 or num * num) work it says it up above about what to do.
def squared(num): if num == int: return(num ** 2) else: return(num * num) # squared(5) would return 25 # squared("2") would return 4 # squared("tim") would return "timtimtim"
Bryan Reed11,013 Points
In the instructions it's basically giving you an option to use either num ** 2 or num * num as your return if the argument can be converted into an integer, since either operation returns the same result. Example:
try: return int(argument) ** 2 # Or if you wanted in the above return you could do # return int(argument) * int(argument) except ValueError: return argument * len(argument)
The part that your missing in your code is the last sentence of the challenge "If the argument cannot be turned into an integer (maybe it's a string of non-numbers?), return the argument multiplied by its length. Look in the file for examples."
Hope that helps! :)