Practice Makes Perfect


Error = "cube(1) resulted in an error: maximum recursion depth exceeded"

def cube(number):
    if cube(number)==1:
        return number ** 3

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


this line:

if cube(number)==1:

you call the function, which means you will endless call the function (maximum recursion depth)

I would simple check if the parameter (number) passed into the function equals 1:

if number == 1


I did that. It just gave me this: cube(2) returned None, did you remember to return the result?

I edited my code before this when I saw the responses to another post with the same problem as me.


why do you even have a if condition in the cube function? I don't see this anywhere in the instructions, remove the if condition from your cube function


Oh. I thought it wasn't either but the image above the instructions was showing something different so I got confused. Thank you for your help thought! :slight_smile:


but if the image is an exact match, you have to do no thinking at all, that isn't good. Issue resolved?


Yes. And I've now learned my lesson.