# "practice makes perfect" problem

#1

``````def cube(number):
def by_three(number):
return number ** 3
by_three(cubenumber))
if number % 3 == True:
by_three(number)
return by_three
print "n is divisible by 3"
else:
return False
print "n isnt divisible by 3"``````

it keeps saying cube(1) resulted in an error: maximum recursion depth exceeded

#3

so I changed it a bit but now it replies "cube(1) returned False instead of 1

#4

There are two functions involved in this program. `cube()` and `by_three()`.

``````def cube():
return

def by_three():
return``````

The cube function is straight forward enough, given a `number` argument.

``return number ** 3``

`by_three` requires some decision making, and an `if..else` scenario.

``````if number % 3: return False
return cube(number)``````

But wait, there is no `else`! Because we don't need one when the `if` case has a return statement. Flow essentially falls through the `if` and on to the final return statement.

Were there not a return statement in the `if` block, then `else` would be an absolute requirement. This is why return is such a great tool.

#5

Thanks!

#7

this helped a lot thank you for walking through it

#10

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