[SOLVED] Expected An Indented Block - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: [SOLVED] Expected An Indented Block (/thread-10788.html) |
[SOLVED] Expected An Indented Block - Panda - Jun-06-2018 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) # PlaceholderOn the line else if console == 'Y':i get the error 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 What am i supposed to do to fix this? If i manage to fix one, the rest will probably return the same error.
RE: Expected An Indented Block - Larz60+ - Jun-06-2018 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 RE: Expected An Indented Block - buran - Jun-06-2018 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 placeholderhowever more pythonic would be something like if console.lower() in ('y', 'yes'): pass # now, that is a placeholder RE: Expected An Indented Block - Panda - Jun-06-2018 (Jun-06-2018, 06:36 PM)Larz60+ Wrote: indents are 4 spaces per level. 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 instead of as well.(Jun-06-2018, 09:16 PM)Panda Wrote:(Jun-06-2018, 06:36 PM)Larz60+ Wrote: indents are 4 spaces per level. 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. RE: [SOLVED] Expected An Indented Block - Larz60+ - Jun-06-2018 it's elif not else if |