3

Here's my code:

def options():
    selection=int(input("#>"))
    if selection == 1:
        #Connect

    elif selection == 2:
        #Modules
        print("Modules")

    elif selection == 3:
        #Checking Internet
        checkInternetConnection()

    elif selection == 99:
        #Exit
        shutdown()
    else:
      print "Unknown Option Selected!"
      sleep(100)
      sys.clear()
      start()

Every time I run i get this error:

  File "main.py", line 41
    elif selection == 2:
       ^
IndentationError: expected an indented block

I am probably being a noob here but please may someone help?! Thanks

Will
  • 63
  • 4

4 Answers4

3

There has to be a statement after your if block

Note: Comments don't count. You can use pass statement instead.

eg.

if statement:
    pass
2

While that indebted # Connect looks like a perfectly good if body to you, and to other human readers, to Python it‘s as if you had nothing there at all. And an empty if body is illegal.

There are two common ways to handle this, and you’ll want to get into the habit of doing one or the other without thinking, whenever you need to stick in a placeholder for code to be written later, or temporarily disable some code for debugging.

The first is to write this:

pass # TODO: Connect

The second is to write this:

"Connect"

The latter may look kind of weird (even if you’re used to docstrings), but it is a perfectly valid expression, and therefore a perfectly valid statement.

While you could just write pass # Connect, the problem with that is that pass and a comment is something you could reasonably have in your final code, so you have no way to tell whether this was a placeholder you meant to come back to before deploying anything.

By contrast, your linter/IDE/commit-hooks/CI/whatever can easily be configured to recognize either TODO comments, or expression statements that have no effect, and therefore warn you to double-check that this code really is ready to deploy.

abarnert
  • 354,177
  • 51
  • 601
  • 671
1

Comments are not placeholders for if statements so use pass.

...
if selection == 1:
    #Connect
    pass
...
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
0

Where you have #connect, put some functional code under that if instead or with it. Its reading that the elif is ' under ' the if.

Zac
  • 1,719
  • 3
  • 27
  • 48