Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

IndentationError: unindent does not match any outer indentation level ? how to fix this

While compiling Python code below, I get this error
IndentationError: unindent does not match any outer indentation level
import sys
def Factorial(n): # Return factorial
result = 1
for i in range (1,n):
result = result * i
print "factorial is ",result
return result
Any reason ?
by

3 Answers

Kajalsi45d
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)
sandhya6gczb
Unlike other languages like Java and C++ where curly braces are used for representing a block of code, Python uses indentation to represent a block. The above program is not properly indented. So correct the program.

import sys
def Factorial(n): # Return factorial
result = 1
for i in range (1,n):
result = result * I
print "factorial is ",result
return result

pankajshivnani123
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 :-)

Login / Signup to Answer the Question.