• Register
0 votes
206 views

Problem :

When I try to compile my Python code below, I get below error

“IndentationError: unindent does not match any outer indentation level”

import sys

def Factorial(n): # Return the factorial

    myresult = 1

    for j in range (1,n):

        myresult = myresult * j

    print "The factorial is: ",myresult

    return myresult

 

Why am I getting above error?

3.9k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Other posters are probably correct...there are may be spaces mixed in with the tabs. Try doing the search & replace to replace all the tabs with a few spaces.

Try as below :

import sys
def Factorial(n): # Return the factorial
   myresult = 1
    for j in range (1,n):
        myresult = myresult * j
    print "The factorial is: ",myresult
    return myresult
print Factorial(10)

 OR

For the Sublime Text users:

Set the Sublime Text to use tabs for your indentation: View --> Indentation --> Convert Indentation to Tabs

Uncheck a Indent Using Spaces option as well in a same sub-menu above. This will immediately fix your issue.

OR

To easily check for the problems with your tabs/spaces you can actually do as below:

python -m tabnanny yourfile.py

Or you can just set up the editor correctly of course.

I hope the above given solutions will help you in resolving your all of the errors.

38.6k points

Related questions

0 votes
1 answer 21 views
21 views
Problem: Please help me to solve it .. Indentationerror: unindent does not match any outer indentation level python
asked Apr 3 Ifra 43.4k points
0 votes
1 answer 11 views
11 views
Problem: When I compile the Python code below, I get > Indentationerror unindent does not match any outer indentation level
asked May 3 ochena 23.3k points
0 votes
1 answer 10 views
10 views
Problem: What is wrong here : Unindent does not match any outer indentation level in python?
asked Jun 22 Priscilla Gurpreet 74.7k points
0 votes
1 answer 1 view
1 view
Problem: Has anyone had this issue before : Unindent does not match any outer indentation level python error?
asked Jun 20 nila 121k points
0 votes
1 answer 16 views
16 views
Problem: I'm trying to figure out a solution, need help >Unindent does not match any outer indentation level python.
asked May 9 Florina Gulnar 106k points
0 votes
1 answer 69 views
69 views
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?
asked Jan 6 Mashhoodch 13k points
0 votes
1 answer 155 views
155 views
Problem : When I compile the Python code I get below error IndentationError: unindent does not match any outer indentation level
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 9 views
9 views
Problem: When I compile the Python code below, I get IndentationError: unindent does not match any outer indentation level Thanks
asked Mar 16 ummesalma 29.1k points
0 votes
1 answer 11 views
11 views
Problem : Unindent does not match any outer indentation.
asked Jul 6 Isac Christiaan 103k points
0 votes
1 answer 8 views
8 views
Problem: Is it possible to make this work : Terror: inconsistent use of tabs and spaces in indentation python?
asked Jun 18 Nahil 128k points