Functions, Practice makes perfect

#1

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

#2

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)

#3

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

Thanks for your help

#4

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

#5

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

#6

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.

#7

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.

#8

`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.

#9

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

#10

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