Practice Makes Perfect - "What is wrong with this code?"


#1

Can someone please tell me what is wrong with this code?

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

It prints this error:

File "python", line 6
else:
^
SyntaxError: invalid syntax

Any idea why?


#2

the indention of else is wrong, it should be an if/else so if and else should be at the same indent level


#3

Thanks, that had me confused for a while!


#4