6. Practice makes perfect Please Help


#1



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


I get the error message: Traceback (most recent call last):
File "python", line 10, in
File "python", line 2, in cube
TypeError: unsupported operand type(s) for ** or pow(): 'function' and 'int'


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


#2

inside your cube function:

return cube ** 3

you do the function ^ 3? looks a bit weird, cube is the function. use the function parameter instead (number)


#3

It doesn't seem to work, I got this error message: Oops, try again. cube(1) resulted in an error: unsupported operand type(s) for ** or pow(): 'function' and 'int'


#4

He's talking about the first function.

TypeError: unsupported operand type(s) for ** or pow(): 'function' and 'int'

We can't have a 'function' to the power of 'int'.


#5

the code i posted only shows where the mistake is, not the solution.

@n00borg is absolutely right. Good answer n00borg


#6

Wait so it should be
def cube(return cube ** 3)

Im really not understanding this.


#7

no this line:

return cube ** 3

you try to the function to the power of three. You should do number to the power of three, number is the function parameter, which you can pass a number when calling the function


#8

Thanks I have no idea why I was so confused by this :smiley:


#9