HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonCriticalCanonical

IndentationError: unindent does not match any outer indentation level, although the indentation looks correct

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
indentationerrorlevelanylooksindentationthecorrectdoesnotalthough

Problem

When I compile the Python code below, I get

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


Why?

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:

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.