Can someone tell me whats wrong with my code, apparently the else statement doesn't work


def cube(number):
return number*number*number

def by_three(number):
if number/3:
return cube(number)
return False


In what way does it not work? Explain what it is doing differently from what you want.

You're dividing number by 3 and then treating the result as a boolean. That's valid code, but perhaps not what you want to be doing. Perhaps you would rather compare the result to some other value? And if you're investigating divisibility then modulus will serve you better than division.. division can tell you if something is divisible but you'll have to do a couple of more operations to make that happen - i suggest trying to come up with a way to do that with pen and paper if you choose that route. Modulus does most of it for you though.

Also use prints to follow along in what your code does if you're not sure.

And if you post code, make sure it's intact.


you have to type:
if number%3==0:
return cube(number)
return False