python – IndentationError: unindent does not match any outer indentation level
python – IndentationError: unindent does not match any outer indentation level
Other posters are probably correct…there might be spaces mixed in with your tabs. Try doing a search & replace to replace all tabs with a few spaces.
Try this:
import sys
def Factorial(n): # return factorial
result = 1
for i in range (1,n):
result = result * i
print factorial is ,result
return result
print Factorial(10)
IMPORTANT:
Spaces are the preferred method – see PEP 8 Indentation and Tabs or Spaces?. (Thanks to @Siha for this.)
For Sublime Text users:
Set Sublime Text to use tabs for indentation:
View –> Indentation –> Convert Indentation to Tabs
Uncheck the Indent Using Spaces option as well in the same sub-menu above.
This will immediately resolve this issue.
python – IndentationError: unindent does not match any outer indentation level
To easily check for problems with tabs/spaces you can actually do this:
python -m tabnanny yourfile.py
or you can just set up your editor correctly of course 🙂