6. Practice Makes Perfect. need help completing



Oops, try again. by_three(1) resulted in an error: maximum recursion depth exceeded

error message i keep getting. not sure what it means. any help would be greatly appreciated.

number = raw_input("Enter a number")

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


maybe try calling cube(number) and return commands on separate lines.

    return False

^ this ended up fixing it ^


This section contains the problem. Recursion is the name for calling a function with the same function (Calling 'by_three' in 'by_three'). Recursion is like a for-loop in the sense that it needs a break to avoid being infinite which is what is currently happening in your code.
The easiest solution is to remove the recursion and then fix the indent of the return statement.

Hope this helps! If not, feel free to reply and I'll try to go more in-depth.


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