Practice makes perfect problem


Help please, I'm stuck on Practice makes perfect and even after looking through other people's posts on this issue I seem unable to solve the problem. The error code is:

Oops, try again. cube(1) resulted in an error: maximum recursion depth exceeded

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

I've tried just about everything i can think of and even just tried to make my code as perfect as possible but i always end up with that error code


Check your if statement. when you use % on something you return the remainder. So what remainder would you need to prove something is cubed?

if number % 3 == ?


good work man :smiley:


so i changed the code to if number % 3 == 0: but i still get the same error message, is there anything else i'm doing wrong?


The error refers to the def cube(number) function, you return the function itself without a terminating condition so it keeps calling itself.


The beginning of the code, you have it typed up as:

def cube(number):
    return cube(number)

As @airfish said, you are calling it over and over again. Remember that the instruction says to return the "number" of the function, not the full function name. Also, the instruction is asking for the cube of that number. What do you have to enter in order to get a cube of a number?


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