我是 Python 的初学者。我写了如下代码只是为了练习..请看
i=1
def wrte():
global i
while i<5:
print "%s .Line..\n" %i
i+=1
def appnd():
j=i
while i in range(i,j+3):
print "%s .Line..\n" %i
i+=1
def Main():
wrte()
appnd()
Main()
输出如下
1 .Line..
2 .Line..
3 .Line..
4 .Line..
**Traceback (most recent call last):
Line 18, in <module>
Main()
Line 16, in Main
appnd()
Line 9, in appnd
j=i
UnboundLocalError: local variable 'i' referenced before assignment**
预期结果:: 下一个序列应该像这样附加
5. Line..
6. Line..
7. Line..
请帮我解决这个问题..