What does max recursion depth exceeded mean?

Question

What does max recursion depth exceeded mean?

Answer

If you receive the error maximum recursion depth exceeded, you likely need to rework your cube function. To cube a number, we’re simply multiplying it by itself 3 times. In Python, we’ve seen that we can use ** to raise something to a power. If we wanted to square a number, we could type number ** 2 or number * number. The same logic applies.
Writing return cube(number) is invalid because it calls the cube function, which then calls the cube function, which then… you get the point. It’s an infinite loop of calling itself!

6 Likes