如果执行以下代码将显示错误消息:
UnboundLocalError:分配前引用的局部变量“a”
a = 220.0
b = 4300.0
c = 230.0/4300.0
def fun():
while (c > a/b):
a = a + 1
print a/b
if __name__ == '__main__':
fun()
但修改为:
a = 220.0
b = 4300.0
c = 230.0/4300.0
def fun():
aa = a
bb = b
while (c > aa/bb):
aa = aa + 1
print aa/bb
if __name__ == '__main__':
fun()
会好的。任何建议或指示都会很棒。非常感谢!