SyntaxError at Cloud9 IDE? Is this a bug or did I do something wrong?
<p>I believe I have found a bug with the Cloud9 IDE, as I get a syntax error in the following code: </p>

<pre><code>    for x in optionMenu:
            print x[0], x[1]
        action = raw_input ("Please select an action: ")
        if action == "1":
            direction = directionMenu()
            if direction == "East":
                validAction = True
                print "You raise the portcullis and enter the palace."
                room2(character)
            else:
                print "You can't go that way!"
        elif action == "2":
            characterMenu(character)
        elif action == "3":
            if searched_yet1 == False:
                skill_pass = skillCheck(1, character.search)
                if skill_pass ==  True:
                    print "The double portcullis seems moveable with some effort."
                    searched_yet1 = True
                else:
                    print "You fail to find anything worthy of note. "
                    searched_yet1 = True
            else:
                print "You have already attempted that action!"
        elif action == "4":
            if listened_yet1 == False:
                skill_pass = skillCheck(5, character.listen)
                if skill_pass == True:
                    print "Sounds coming from deep in the palace can be heard every few minutes."
                    listened_yet1 = True

                else:
                    print "You fail to hear anything worth of note. "
                    listened_yet1 = True
            else:
                print "You have already attempted that action!"
</code></pre>

<p>The syntax error occurs at <code>"elif action == "4":</code>. AmI doing something wrong or have I found a bug with the Cloud9 IDE? I have tried adjusting the spacing. Is there an error with the above print statement?</p>

<p>EDIT: Version is Python 2.7.6, error is </p>

<pre><code>File "/home/ubuntu/workspace/dungeonMap.py", line 63
    elif action == "4":
   ^
SyntaxError: invalid syntax
</code></pre>

<p>As I examine your code as posted here, the line <code>elif action == 4:</code> is preceded by 4 spaces then 2 tabs. Mixing spaces and tabs in Python is <em>a very bad idea</em>. I also see that some lines, such as the preceding one, use only spaces for indentation.</p>

<p>Replace those two tabs, as well as any others, with spaces, and configure your IDE to use only spaces when indenting. See if that solves the problem.</p>

<hr>

<p>After looking more closely, I now see the direct problem. I believe that Python treats a tab as 8 spaces, no matter how it appears in your editor. Given that, your line two lines above your problem line is an <code>else:</code> but is indented to conclude the <code>if action == "1":</code> line rather than the <code>if searched_yet1 == False:</code> line that you intended. Python then sees your <code>elif action == 4:</code> line as an <code>elif</code> without a corresponding prior <code>if</code>.</p>

<p>Again, replacing all those tabs with spaces and then getting the indentation to look right will solve that problem and others.</p>

python syntax