Is this correct?


#1

def cube(number):
return number ** number

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

The instructions:

First, def a function called cube that takes an argument called number . Don’t forget the parentheses and the colon!

Make that function return the cube of that number ( i.e. that number multiplied by itself and multiplied by itself once again).

Define a second function called by_three that takes an argument called number .

if that number is divisible by 3, by_three should call cube(number) and return its result. Otherwise, by_three should return False .

Don’t forget that if and else statements need a : at the end of that line!


#2

No, it is not correct because there is a recursion (function calls itself).

return cube(number)

From this we see that we can return a call to a function. The call will take place immediately, so its return value will be what is returned from the by_three() function…


#5

That’s a huge exponent. It should be a 3.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.