Practice Makes Perfect (unusual error)


#1



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


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


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


#2

Hi, @cunycodemaster2k4,

Regarding the cube function, the instructions state ...

Make that function return the cube of that number (i.e. that number multiplied by itself and multiplied by itself once again).

However you have the function call itself, which is an example of recursion.

Consider using the ** operator to perform the math within the function, or using the * operator twice.

In the by_three function, the condition in this if header needs to be revised ...

    if  number %  3:

#3

A post was split to a new topic: Practice Makes Perfect - Error


#4

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