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
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"
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! :)