Trouble with an if/else inside a function


File “python”, line 8
SyntaxError: invalid syntax

  • I am stuck not sure how to proceed with this syntax error on the else statement
def cube(number):
  return number
def by_three(number):
    if number%3==0:
    return number
    return False


If the number % 3 == 0, then return the cube(number). Else, return False.

Now look at your code. You have:

if number % 3 == 0:
return number

The function cube() returns the cubed number. You are calling it correctly; however, you’re not returning it. Look at your code.

Psst…the return you have in the if and else code blocks need to be indented for it to belong to that code block.


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