Help with Practice Makes Perfect


I am stuck on Practice makes perfect. Here's the link:

This is my code:

def cube(number):
     return cube(6)
def by_three(number):
    if n % 3 == 0:
        print result
        print False

The error message comes up as:
Oops, try again. cube(1) resulted in an error: maximum recursion depth exceeded

First of all, what does the error message mean?

Second, What did I do wrong with my code?

Third, How do I fix it?

A big thank you to whoever can answer my questions!


it means the function keeps calling/executing itself, a function calling itself is called recursion. (you can google this if you like), it is cause by this two lines:

def cube(number):
     return cube(6)

it is sort of a infinity loop, but slightly different.

the cube function should return number ^ 3, i suggest applying this to make your code overcome this error message (note: number ^ 3 is math syntax, not python syntax)


Ok,thank you. Truly appreciate your help!!


Did you resolve it? If so, that would be good

If not, see if you can solve it with this new insight i provided, if still stuck after trying this, post an updated version of your code and i will help you further


No, I didn't.....once I tried to apply what you had said, I got stuck without ever reformatting my code. I couldn't understand how I would make the code return number^3.


well, till the power is nothing of multiplying the number by itself a number of times, in this case 3 times:

number * number * number

or you can use ** which allows you to use exponent


OK ......

def cube(number):
    return number ** 3

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

Error message: Oops, try again. by_three(3) returned 3 instead of 27


step 4 of the instructions:

if that number is divisible by 3, by_three should call cube(number) and return its result

You just return number, not the cube of the number


Alright, I got it..... thank you so much for your help!:slight_smile: