Confused man


#1



what is wrong with this?
Exercise is practise makes perfect
Error message appears telling me that when 2 is input, it returns false rather than 8. But isn't that the correct answer


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


#2

Could you post a link to the exercise or the instruction for this one?
The error message is correct that for 2 the output would be false because 2%3 is 2 and not 0.


#3

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


#4

Ok the obvious problem is here:

return number==number**3

this compares number to the cube of this number. Which is always False because unless it number is 0 or 1. Still the error message is confusing as False is what you would expect to receive if the input is 2.


#5

File "python", line 2
return number=number**3
^
SyntaxError: invalid syntax

even if I put a single equals sign, this is the error message I receive


#6

You don't need any equal sign here, you just return the cube of the input. Just number**3


#7

Thank you so much. This really helped


#8

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