python error: local variable 'a' referenced before assignment
<p>I'm trying to create a function with an interactive input to tell you what the 'SMILES' formula is for a fatty acid (chemical compound) but I keep getting this error:</p>

<pre><code>def fatty_gen(chain_length, db_position, db_orientation):
    "Returns the SMILES code of the fatty acid, given its chain length, db position, db orientation"
    chain_length=input("What is the chain length/number of C?")
    chain_length2=int(chain_length)
    db_position = input("On which carbon does the double bond first appear")
    db_position2=int(db_position)
    db_orientation= input("What is the orientation of the double bond")
    db_orientation2=str(db_orientation)

    if db_orientation2 =="Z":
        a="/C=C\\"
    elif db_orientation2=="E":
        a="\C=C\\"
    else: a =""

    return "C"*((db_position2)-1) + a + "C"*(chain_length2-db_position2-1)


&lt;ipython-input-2-20b88ae22368&gt; in fatty_gen(chain_length, db_position, db_orientation)
     13         a="\C=C\\"
     14 
---&gt; 15     return "C"*((db_position2)-1) + a + "C"*(chain_length2-db_position2-1)
     16 fatty_gen(1,1,1)

UnboundLocalError: local variable 'a' referenced before assignment
</code></pre>

<p>UnboundLocalError: local variable 'a' referenced before assignment</p>

<p>If <code>db_orientation2</code> is neither <code>"Z"</code> nor <code>"E"</code> <code>a</code> variable is not defined.</p>

<p>You need to add <code>else</code> clause like this:</p>

<pre><code>if db_orientation2 == "Z":
    a = "/C=C\\"
elif db_orientation2 == "E":
    a = "\C=C\\"
else:
    a = "something else"
</code></pre>

python