Practice Makes Perfect


#1

I don't understand exactly whats wrong with my code, any help would be greatly appreciated.
It keeps returning the error message:

"maximum recursion depth exceeded"

-This is my code:

def cube(number):
return cube(number)**3

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

Note Everything is indented properly in my code


#2

This is where the recursion is happening. The function is calling itself with no base case so runs to infinite (or crash).

According to the name given the function, 'cube' one would expect it to return a cube of number.

return number ** 3

#3

how do i post my problem?


#4

Be sure you are in the correct category that matches the unit you are in. Start a new topic with a brief title that describes the problem.

Post your code in formatted sample, along with the error message. Describe what you are having trouble with and ask a question relating to the problem. Please include a link to the exercise so we can read the instructions and test your code.


#5

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