Need help with Exercise "Practice Makes Perfect"


Hello world,

I'm stuck with this exercise, receiving the error notification as "cube(1) resulted in an error: maximum recursion depth exceeded". This is my code:

def cube(n):
    if n == n ** 2:
        return cube(n)
def by_three(n):
    if n % 3 == 0:
        return cube(n)
        return False

Can anyone please comment on my code?

Many thanks & Cheers,


i don't understand your if statement:

if n == n ** 2:

could you explain the logic? Can you provide the exercise url as well? I need to have a look at the instructions/exercise.

uhm.. the error is caused by this line:

return cube(n)

inside your cube function, the function will endless keep calling itself. You should return n^3


Hi Stetim94,

I created this statement because of the instruction No.2:

Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).

Here is the link please:

Can you please have a look?

Thank you,


yea, so you should return n ^ 3 (n * n * n), so not sure why you need a if statement for it?


So i mis intepreted it? let me try again


I got it thru. Many thanks to you :slight_smile: