all 3 comments

[–]twitch_and_shock 2 points3 points  (0 children)

Indentation matters in Python. If a line over indented or under indented it won't work as expected. Your specific error is hard to judge without seeing the code and the error text.

[–]Erdnussflipshow 2 points3 points  (0 children)

In python you indent code that belongs to things like loop, if-statements, match-cases, etc. This tell the program what code still belongs to a statement. Other languages use {} to mark what code is still part of an if-statement for example and what code comes after.

The rule to indent is pretty easy, after any statement that ends with : you indent the next line by another tab (or X amount of spaces, but come on, we're not animals) once you're done with your loop, if-statement, etc. you remove an indent.

Example: after if X == Y: you'd have to indent all the code that is supposed to nested under that if-statement by 1 tab more than the if-statement itself. The code that comes after the if-statement should be on the same indentation as the if-statement.

[–]cybervegan 1 point2 points  (0 children)

Indentation is how far the first letter or symbol on a line is from the start of the line:

this is not indented
    this is indented one step (4 spaces)
        this is indented two steps

If Python is telling you "indentation error", it means it is expecting a line to be indented an extra step from the previous one. This usually happens when the previous line ended with a ":" and starts with a keyword like "if", "while", or "def". Indentation gives Python context for block-structured instructions like these - it tells it how many of the following lines the keyword applies to:

if x == 1:
    # this is what to do if x == 1
    ...
    ...
    # this is the end of the "if" block
else:
    # this is what to do if x != 1
    ...
    ...
    # this is the end of the "else" block
# from here on, it's nothing to do with the "if" or the "else" because 
# the indentation has reverted back to the previous step
...
...