Python index out of range when missing user user input
<p>I know this is a simple fix--but I can't for the life of me figure out how to fix this IndexError. </p>

<pre><code>def show_status():
    print("\nThis is the " + rooms[current_room]["name"])



rooms = { 

        1 : { "name" : "Highway" ,
              "west" : 2 ,
              "east" : 2 ,
              "north": 2 ,
              "south": 2} ,
        2 : { "name" : "Forest" ,
              "west" : 1 ,
              "east" : 1 , 
              "north": 1 ,
              "south": 1} , 
        }

current_room = 1

while True:

    show_status()

    move = input("&gt;&gt; ").lower().split()


    if move[0] == "go":
        if move[1] in rooms[current_room]:
            current_room = rooms[current_room][move[1]]
        else:
             print("you can't go that way!")
    else:
        print("You didn't type anything!")
</code></pre>

<p>If the user pushes "return" without putting a value in for move, the game crashes with a "List Index out of range".  I don't understand why the "else" isn't catching that in the while loop.   </p>

<p><code>move[0]</code> checks for the first member of the list, and will throw an <code>IndexError</code> if <code>move</code> is an empty, as when the user simply presses enter. You can check that <code>move</code> is true first: if it isn't, the <code>and</code> operator will circumvent the next check.</p>

<p>It seems that you are expecting a user input with one space, causing two members. You should check that <code>len(move) == 2</code> to ensure this.</p>

<p>Amend as follows:</p>

<pre><code># ...
move = input("&gt;&gt; ").lower().split()

if len(move) == 2 and move[0] == "go":
   # the rest
</code></pre>

python indexoutofrangeexception