6. Practice Makes Perfect. need help completing


#1


https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096#

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


#2

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


#3
else:
    return False

^ this ended up fixing it ^


#4

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.


#5

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