"Practice Makes Perfect" 6/19 Check Code Please


#1

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

I’m getting the error “by_three returned 3 instead of 27”

Is there a problem with the code or am I missing something? Or both?

Any and all help is much appreciated!


#2

with indentation this time

def cube(number):

return number ** 3
def by_three(number):

if number % 3 == 0:

cube(number)
return number
else:

return False


#3

What’s wrong with these 2 lines of code? The first line calls the cube function. It runs and then returns back the cubed number. What happens to that returned cubed number?

Think about it.

To discover for yourself, put a print number between the 2 lines of code. Does the number change?


#4

I was working on it again today and the website gave me the correct code, I saw I was returning the “number” variable inside the “by_three” function and not the “number” variable from the cube function. I see now I should’ve returned “cube(number)”.

Thank you for your help!


#5

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