patternpythonCriticalCanonical
IndentationError: unindent does not match any outer indentation level, although the indentation looks correct
Viewed 0 times
indentationerrorlevelanylooksindentationthecorrectdoesnotalthough
Problem
When I compile the Python code below, I get
IndentationError: unindent does not match any outer indentation level
Why?
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 resultWhy?
Solution
One possible cause for this error is that there might be spaces mixed with tabs for indentation. Try doing a search & replace to replace all tabs with a few spaces.
Try this:
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)Code Snippets
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)Context
Stack Overflow Q#492387, score: 871
Revisions (0)
No revisions yet.