What is wrong with this user defined function


#1

This is the link to the exercise: https://www.codecademy.com/courses/learn-python/lessons/functions/exercises/practice-makes-perfect?action=resume_content_item

It is a user defined functions with embeded fucntions.
I am testing this block of code and that’s what I get:

def cube(number):
  number = number**3
  return number

def by_three(number):
    if number%3 !=0:
    x =0
    return x
  else:
    x = cube(number)
    return x
  
y = by_three(3)
print str(y)

The output is:

File “python”, line 11
return x
^
IndentationError: unindent does not match any outer indentation level


#2

Hi @mghanem8800,

Is the code that you posted the same as the code that raised this error?:

File “python”, line 11
return x
^
IndentationError: unindent does not match any outer indentation level

The code that you posted raises this error instead:

  File "python", line 7
    x =0
    ^
IndentationError: expected an indented block

Line 7 is this one:

    x =0

Check the indentation of the previous line. By how many spaces is that if block header indented? Does it need to be indented by that many spaces? Compare it to the indentation of the header of the corresponding else block.