Practice makes perfect (Needs Debug)


#1
python

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

It should return 27, but instead returns 3.

#2

You need to call your cube function.


#3

is this not it? This is what the lesson said to do.


#4

You have called your by_three method in your last line, but you have not called your cube method anywhere.


#5

However, In the previous lesson, it specifically told me how to do this:


#6

I am not sure you understand what “calling a function” means.


#7

Calling the cube function on the by three function returns 27, but the lesson won’t accept that.


#8

I see what your problem is. Basically, you are not calling “cube”, as “overcantor” mentioned in your “by_three” function. The code should read something like:

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


#9

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