'Practice Makes Perfect' error confused me



I have run into an error during this exercise which I don’t understand. Down below are the instructions.

1.First, def a function called cube that takes an argument called number. Don’t forget the parentheses and the colon!
Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).
Define a second function called by_three that takes an argument called number.
if that number is divisible by 3, by_three should call cube(number) and return its result. Otherwise, by_three should return False.
Don’t forget that if and else statements need a : at the end of that line!

My code (below) gives this error:

cube(1) resulted in an error: maximum recursion depth exceeded

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

What does this error mean? Also, are there any suggestions to being able to fix it?


I have figured out the error, the calling of the function

return cube(number)

on line 3 was redundant, calling the function inside of the function was my problem. Instead I simply did

return number ** 3

also, lines 6 & 7 should be switched to

return cube(number)

(making it one line instead of the original two)


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