# 6 Practice Makes Perfect - Why use return in by_three( ) function?

Here’s my final code which I got correct.

def cube(number):
return number ** 3

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

The first time I coded it however, I did the following:

def cube(number):
return number ** 3

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

I got the error that it returned “None”. My confusion is this: If def_cube already returns number ** 3, why do I have to again use return in the if statement inside by_three?

If `by_three` calls `cube`, and `cube` returns, then control of the program is back in `by_three`

If `by_three` is to return anything, then there needs to be a return statement in `by_three`

`return` only exits the current function, it doesn’t cause all functions currently on the stack to exit

I was thinking it was something like this but your explanation makes it very clear, thanks.

I did exactly like you, but it gives me error on line 4.

def cube(n):
return n**3

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

I think the best answer for the exercise is

def cube(number):
return number**3

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

1 Like

im sorry, but why you write ==0?

1 Like

I was wondering the same thing…does this code look ok

def cube(number):
return number**3

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

can anyone please show me the right one so I can compare it with mine to c what is wrong

it still dsnt work…wht to do???

it says
File “python”, line 2
return number ** 3
^
IndentationError: expected an indented block

Hi everyone,

I have the below formula, however, I have a question why does it need the semi colon after return cube(number);
I want to understand the idea behind this, why does a colon not work here for example?.
thx

def cube(number):
“”“returns a cube value to the console”""
return number **3

def by_three(number):
“”“checks if the number is divisible by 3 and returns the value”""
if number % 3 == 0:
return cube(number);
else:
return False

it dsnt work aarrgghh

hi

def cube(number):

``````return number**3
``````

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

its correct