Python Forum
[SOLVED] Expected An Indented Block
Thread Rating:
  • 3 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Expected An Indented Block
#1
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.
Self-taught HTML, CSS, Python, and Java programmer
Reply
#2
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
Reply
#3
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
(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.
Self-taught HTML, CSS, Python, and Java programmer
Reply
#5
it's elif not else if
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write in text file - indented block Joni_Engr 4 6,362 Jul-18-2022, 09:09 AM
Last Post: Hathemand
  how far is this line indented? Skaperen 3 1,289 May-30-2022, 05:49 PM
Last Post: Skaperen
Thumbs Up [SOLVED] Simplify condition test in if block? Winfried 2 1,675 Aug-25-2021, 09:42 PM
Last Post: Winfried
  [SOLVED] [geopy] "ValueError: too many values to unpack (expected 2)" Winfried 2 2,835 Mar-30-2021, 07:01 PM
Last Post: Winfried
  error "IndentationError: expected an indented block" axa 4 2,859 Sep-08-2020, 02:09 PM
Last Post: ibreeden
  IndentationError: expected an indented block ryder5227 2 2,562 Sep-27-2019, 06:59 PM
Last Post: jefsummers
  SOLVED: best way to block (wait on) shell calls to multiple windows programs at once? ezdev 0 2,578 Dec-10-2017, 06:42 AM
Last Post: ezdev
  Expected an indented block Nicoles07 2 3,376 Sep-15-2017, 05:19 PM
Last Post: deaspo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020