Python Forum

Full Version: [SOLVED] Expected An Indented Block
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is my code:
    if console == 'y':
                # Placeholder
                pass
            elif console == 'Y':
                # Placeholder
                pass
            elif console == 'n':
                # Placeholder
                pass
            elif console == 'N':
                # Placeholder
                pass
            elif console == 'Exit':
                sys.exit(0)
            else:
                print('Unknown Command')
                sys.exit(0) # Placeholder
On the line
else if console == 'Y':
i get the error
Error:
SyntaxError: Expected An Indented Block
I'm using IDLE, so i'm getting told its a problem with the "else" in
else if console == 'Y':
I don't understand what I'm supposed to do. If i indent the line, i get the error
Error:
SyntaxError: Invalid Syntax
What am i supposed to do to fix this? If i manage to fix one, the rest will probably return the same error.
indents are 4 spaces per level.
In addition, you need at least a 'pass' command after each condition
if console == 'y':
    # Placeholder
    pass
else if console == 'Y':
    # Placeholder
    pass
else if console == 'n':
    # Placeholder
    pass
else if console == 'N':
    # Placeholder
    pass
on the second row you need to put what will be executed in case the condition is True.
so it will look like
if console == 'y':
    print('you entered {}'.format(console))
elif console == 'Y':
    pass # now, that is a placeholder
elif console == 'n':
    pass # now, that is a placeholder
elif console == 'N':
    pass # now, that is a placeholder
else:
    pass # now, that is a placeholder
however more pythonic would be something like
if console.lower() in ('y', 'yes'):
    pass # now, that is a placeholder
(Jun-06-2018, 06:36 PM)Larz60+ Wrote: [ -> ]indents are 4 spaces per level.
In addition, you need at least a 'pass' command after each condition
if console == 'y':
    # Placeholder
    pass
else if console == 'Y':
    # Placeholder
    pass
else if console == 'n':
    # Placeholder
    pass
else if console == 'N':
    # Placeholder
    pass

I have 4 spaces per indent, but i added the pass.

Now it highlights the if in
else if console == 'Y':
instead of the else

I'm getting
Error:
Invalid Syntax
instead of
Error:
Expected an Indented Block
as well.

(Jun-06-2018, 09:16 PM)Panda Wrote: [ -> ]
(Jun-06-2018, 06:36 PM)Larz60+ Wrote: [ -> ]indents are 4 spaces per level.
In addition, you need at least a 'pass' command after each condition
if console == 'y':
    # Placeholder
    pass
else if console == 'Y':
    # Placeholder
    pass
else if console == 'n':
    # Placeholder
    pass
else if console == 'N':
    # Placeholder
    pass

I have 4 spaces per indent, but i added the pass.

Now it highlights the if in
else if console == 'Y':
instead of the else

I'm getting
Error:
Invalid Syntax
instead of
Error:
Expected an Indented Block
as well.

I made a mistake in my coding. I code in Atom, but run programs in IDLE, so the file didn't save when i added the pass. The program runs successfully.
it's elif not else if