Practice Makes Perfect


#1


https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096

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)
    else: 
        return False


#2

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

#3

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.


#4

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


#5

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:


#6

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


#7

Yes. And I've now learned my lesson.