Indentation error

How do I correct an indentation error on the Replit platform?
What steps do I need to follow or what configurations do I need to make? :worried:

:wave: Hey @yullypop20, welcome to the forums!

Can you please provide a link to the Repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

3 Likes

In your code, be sure to use the same number of spaces for each level of indentation. The number of spaces for an indent can be configured in Settings, then you can press tab to indent easily.
Make sure you use the correct number of indentation levels. If it is inconsistent or incorrect, there may be an indentation error.
Also, an if statement cannot have any more clauses after an else clause.

if thing:
    if other_thing:
        print('hi')
elif option:
        print('hello')  # <- prone to error: 2 indents instead of 1
else:
    ...
elif option2:  # <- causes an error: cannot put another elif
    print()

Actually, that code will run fine[1]. Possible indentation issues are:

if xyz:
    function1(abc, eod)
  function2(lkd, bsj) # Indentation error
# OR
if xyz:
    function1(abc, eod) # Spaces
    function2(lkd, bsi) # Tabs
# ^ Inconsistent use of tabs and spaces in indentation error

  1. Python will not care, as long as it’s indented consistently within the given block ↩︎

2 Likes

Whoops, I’ll edit that.

The only repl I can find has a problem with the if statements: the else clause must be the last clause of an if statement and you cannot put any more elif or else clauses after it.

2 Likes