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
Similar issue here; return x was indented with multiple spaces where as my new code above it used tab.
1 comments
thanks~ it worked
Answer 50d1048337d7565a49001c71
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.
1 comments
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
erase everything and then manually retyp it. Worked for me for some reason.
1 comments
I Reset the window and retyped entire function def again. It worked.
Answer 5095bf9c6b51630200003ce4
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
1 comments
I have done the same as you and it worked now.
Answer 5098e9645e46020200004397
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.
1 comments
Isn’t the CodeAcademy Python track only for Python 2.7?
Answer 507d648027379002000023a6
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?
Answer 507d849b7fde6602000030b3
I had the same problem. I put a space before and after the += and it worked.
1 comments
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
I came back and tried again today and it works. May have been a bug.
Answer 50b8b28fab86d27ec1001032
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.
Answer 50bcef81b01058272500143f
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..
Answer 50bdd5b28121a0920e001e09
Erasing the line ‘return x’ and retyping it manually worked for me,
Popular free courses
- Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly4 Lessons - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly11 Lessons - Free course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner Friendly6 Lessons