Functions, Practice makes perfect


The console box does not show any errors but a message keeps on appearing, saying that maximum recursion depth has increased for by_three(1), I really don't understand what that means.

Why wouldn't the code run normally?

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


because here:

return by_three(cube(number))

you call the by_three function inside the by_three function, this is known as recursion

because there is no base case, this recursion will go on until the maximum depth is reached (sort of like an infinity loop)


So what is the correct code to write? i am stuck here too.

Thanks for your help


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


I still am not sure what the right code to write is. Thanks!


okay, so you hijack a topic (which is against the guideilnes), i literally already posted the solution, what do you expect me to say?

i am going to be honest, i am not sure how to respond to this. Your reply doesn't include much information for me to work with.


Sorry, I don't understand what you meant by 'call cube(number) and return its result'. Sorry again but I am new to coding and still don't understand most of it. :frowning:


cube() is clearly a function call, the function call cube() will return a result, which in turn by_three must return if number is divisible by 3.


Thank you very much and sorry for any problems i have caused!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.