Skip to content
Sign upLog in
← Back to Community

IndentationError: unexpected indent

Profile icon
adsarebbbad

why does my repl give an error even though its fine?

Answered by CodingCactus [earned 5 cycles]
View Answer
Voters
Profile icon
NoahVan13
Profile icon
AdityaShukla19
Profile icon
undetectable
Profile icon
dabs364
Profile icon
MemeManHimself
Profile icon
adsarebbbad
Comments
hotnewtop
Profile icon
CodingCactus

Yeah, that is nowhere near fine, why is the whole code indented so much?

Profile icon
adsarebbbad

@DynamicSquid
told me to do it to fix an error
@CodingCactus

Profile icon
adsarebbbad

do you know how to revert it?

@CodingCactus

Profile icon
CodingCactus

@adsarebbbad
i highly doubt they told you to indent that much

ive fixed it here https://repl.it/@CodingCactus/py-text-game

Profile icon
adsarebbbad
Profile icon
CodingCactus

@adsarebbbad
no problem.
make sure to remember mark it as the answer if it is.

Profile icon
adsarebbbad

now that i added another if statement it says IndentationError: unindent does not match any outer indentation level

@CodingCactus

Profile icon
adsarebbbad

sorry to bother you

@CodingCactus

Profile icon
CodingCactus

@adsarebbbad
that means that you are using a different type of indent to indent (tab or space)

Profile icon
adsarebbbad

which one am i supposed to use?

@CodingCactus

Profile icon
CodingCactus

@adsarebbbad
it doesn't matter, just only use one type in the whole repl

Profile icon
adsarebbbad

could you please make a fixed version? it would help a lot 'cause i dont know how to fix it

@CodingCactus

Profile icon
Coder100

What is up with that much indentation?

Profile icon
adsarebbbad

ctrl + a
tab
shift + tab and thats how you get it

@Coder100

Profile icon
fillermark

As the error message indicates, you have an unexpected indent error . This error occurs when a statement is unnecessarily indented or its indentation does not match the indentation of former statements in the same block. Python not only insists on indentation, it insists on consistent indentation . You are free to choose the number of spaces of indentation to use, but you then need to stick with it. If you indent one line by 4 spaces, but then indent the next by 2 (or 5, or 10, or ...), you'll get this error.

However, by default, mixing tabs and spaces is still allowed in Python 2 , but it is highly recommended not to use this "feature". Python 3 disallows mixing the use of tabs and spaces for indentation. Replacing tabs with 4 spaces is the recommended approach for writing Python code .

Profile icon
adsarebbbad

you're 3 months late

@fillermark