Maximum Recursion Depth exceeded


#1

Hi, I am getting more issues now... I've done as the code asked, also had a look to see if I could find a solution from someone else's post, but I can't. I'm getting the maximum recursion depth exceeded error and I have no idea why or how to correct that.

The link to the exercise is: https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096#

Any help would be most welcome.

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

I've just edited my code to try and fix it, so that I am not calling the function within the function (on the first block) anymore, and now it is saying that the output is 2 when it should be 8. How do I remedy this? I'm not being lazy, I have googled too.


#2

inside the cube function, you should still return cubed. Just make sure the function call is outside the function, and also post an updated version of your code


#3

I think it is because you return cube(number), which is the starting number (2) instead of 2 cubed
try to :
return number ** 3

or

cubed = number**3
then
return cubed


#4

Thanks for your help stetim94, and thank you affanhafizan. You were correct, it was because I was just returning cube(number).