Profile image of shakeystacey
Submitted by shakeystacey
almost 12 years

3.3 IndentationError: unindent does not match any outer indentation level

n = [3,5,7]
def myFun(x):
    x[1]+=3
    return x
print myFun(n)

I get the error : File “python”, line 2 def myFun(x): ^ IndentationError: unexpected indent Oops, try again. Make sure myFun adds 3 to the second element of the list.

Answer 5089b0fec99505020000152c

15 votes

Permalink

Similar issue here; return x was indented with multiple spaces where as my new code above it used tab.

Profile image of eberan
Submitted by eberan
almost 12 years

1 comments

Profile image of Adefyer
Submitted by Adefyer
over 11 years

thanks~ it worked

Answer 50d1048337d7565a49001c71

4 votes

Permalink

As few may have mentioned, the ‘return x’ line uses spaces instead of a tab therefore you must either use spaces when trying to do ‘x[1] += 3’ or erase the spaces for ‘return x’ and tab it.

Profile image of dataWhiz63549
Submitted by dataWhiz63549
almost 12 years

1 comments

Profile image of digitalSurfer02278
Submitted by digitalSurfer02278
over 11 years

Thank you! I just backspaced on the two lines after the ‘def’ statement then indented using the space bar and it worked perfectly.

Answer 509e4a99bed3b90200001074

2 votes

Permalink

erase everything and then manually retyp it. Worked for me for some reason.

Profile image of Jordi2
Submitted by Jordi2
almost 12 years

1 comments

Profile image of megaRunner45051
Submitted by megaRunner45051
over 11 years

I Reset the window and retyped entire function def again. It worked.

Answer 5095bf9c6b51630200003ce4

1 vote

Permalink

Same issue, tried Sidi0u5’s code, didn’t work, deleted the whitespace between “def myFun(x):” and “x[1] += 3”, then added it again, still no luck. Then deleted the whitespace between “x[1] += 3” and “return x”, then added it again, and it worked.

Seems to be some sort of bug

Profile image of Auslegung
Submitted by Auslegung
almost 12 years

1 comments

Profile image of SantiagoPortnoi
Submitted by SantiagoPortnoi
almost 12 years

I have done the same as you and it worked now.

Answer 5098e9645e46020200004397

1 vote

Permalink

My approach is to try out code in IDLE if it does not seem to work in the CodeAcademy window. I got the indentation error described above when using CodeAcademy, put the same code into IDLE and it worked fine. I then tried it again in CodeAcademy, making sure I left a blank line after return x. This made CodeAcademy ecstatically happy - or at least it allowed me to move on. Recommend using IDLE alongside CodeAcademy especially if you are using Python 3.

Profile image of cfrench
Submitted by cfrench
almost 12 years

1 comments

Profile image of Alchemisto
Submitted by Alchemisto
almost 12 years

Isn’t the CodeAcademy Python track only for Python 2.7?

Answer 507d648027379002000023a6

0 votes

Permalink

n = [3,5,7]

def myFun(x): x[1] += 3 return x print myFun(n)

This code worked fine for which appears to be the exact same as yours. Maybe try indenting everything again?

Profile image of Sidi0u5_4f2d512baafc6e0001012e32_deleted
almost 12 years

2 comments

Profile image of GrandPanj
Submitted by GrandPanj
almost 12 years

any idea why mine didn’t work? def myFun(*args): newArgs = args[0][1] newArgs += 3 return newArgs

gave me a few errors, and wouldn’t pass me

Profile image of GrandPanj
Submitted by GrandPanj
almost 12 years

actually, it just printed ‘8’, didnt print the rest of the list

Answer 507d849b7fde6602000030b3

0 votes

Permalink

I had the same problem. I put a space before and after the += and it worked.

Profile image of frances
Submitted by frances
almost 12 years

1 comments

Profile image of davidm
Submitted by davidm
almost 12 years

Try putting a blank line after “return x”. I got the same error, and I think python sees “print myFun(n)” as part of the function if there isn’t the blank line.

Answer 5084148d8b1980020000499d

0 votes

Permalink

I came back and tried again today and it works. May have been a bug.

Profile image of shakeystacey
Submitted by shakeystacey
almost 12 years

Answer 50b8b28fab86d27ec1001032

0 votes

Permalink

This might sounds like crazy talk, but comb through the existing code when you get an error like this. If you’re code uses a different style of white spaces, then match theirs. If they use spaces, you use spaces. If they use tabs, you use tabs.

Some other languages on the site complain about a mixture of spaces and tabs. Python really should too since it results in errors.

Profile image of gjjones
Submitted by gjjones
almost 12 years

Answer 50bcef81b01058272500143f

0 votes

Permalink

n = [3,5,7] def myFun(x): ——-x[1] += 3 ————–return x print myFun(n)

I indented ‘return’ to the variable change and it seemed to work. This seems odd to me. I was under the impression that you ‘returned’ functions and so should be indented as such..

Profile image of Fishermoon
Submitted by Fishermoon
almost 12 years

Answer 50bdd5b28121a0920e001e09

0 votes

Permalink

Erasing the line ‘return x’ and retyping it manually worked for me,

Profile image of TheIrieProject
Submitted by TheIrieProject
almost 12 years

Answer 51247ef94416374998001992

0 votes

Permalink

Same here. Deleting the spaces, then tabbing over on the return x line fixed it.

Things like this are maddening to someone who just can’t figure out what the issue is. Please fix.

Profile image of zenosdog
Submitted by zenosdog
over 11 years