python定义变量不赋值_python错误:在赋值之前引用的局部变量'a'

我试图用交互输入来创建一个函数来告诉你什么'SMILES'公式是脂肪酸(化合物),但我一直得到这个错误:python错误:在赋值之前引用的局部变量'a'

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)

in fatty_gen(chain_length, db_position, db_orientation)

13 a="\C=C\\"

14

---> 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

UnboundLocalError:本地变量赋值

2016-10-15

vluos

+1

如果未执行'if'块,则'a'将会被定义为 –

+0

@MosesKoledoye在这种情况下,为什么'if/elif'不被执行,尽管它在我的函数下? –

+1

大概价值既不是Z也不是E. –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值