[solved]practice makes perfect


#1

Hello guys,

I have ran out of ideas, could someone help me with the code, what I am doing wrong:

Code:

def cube(number):
    return number == number ^ 3
def by_three(number):
    if number % 3 == 0:
        print "%s is divisible by 3" % (number)
    else: 
        print "%s is not" % (number)

Error message:
Oops, try again. cube(1) returned False instead of 1


Practice makes perfect
#2

where to start? lets start here:

return number == number ^ 3

^ is the math operator for to the power of. But python has its own operator for to the power of.

once you fixed that, realize that this line is a comparison, number doesn't equal number to the power of 3, so that is false, so false is returned.

take a look at the instructions what you need to return when the number is (or is not) divisible by three


#3

Thank you very much for your tips!

Reworked code did work:

def cube(number):
return number ** 3
def by_three(number):
if number % 3 == 0:
return number ** 3
else:
return False

Have a nice day mate!


#4

why calculate the cube again? why not call the cube function?


#5

Yes, you are right. Thank you once again!


#6