Confused man


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)
        return False


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.



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.


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


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


Thank you so much. This really helped


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