Practice makes perfect help!


def cube(n):
return n**n

def by_three(n):
if n % 3==0:
print 'divisible by three'
return cube(n)

    print 'number is not divisible by three'
    return False

i was wondering my code looks alright no syntax errors but the console keeps saying that cube(2) returned 4 instead of 8


This returns a number n to the nth power, not a cube of n. Use either,

return n ** 3


return n * n * n


That's because 2 raised to the 2nd power is 4. 3 raised to the third power is 27, which would be right in this instance, but then, 4 to the 4th power, 5 to the 5th power, ... You can see where this is going. There is only one value of n that will satisfy the exercise: 3.


thank you !!!!!!!!!!!!!!!!


A post was split to a new topic: by_three(1) returned None