似乎很多人都会遇到此错误,但每种情况都不同。
我的代码:
i = 0
def sort(a):
b = len(a)
if(i == b):
print (a)
elif(b == 0):
print ('Error. No value detected...')
elif(b == 1):
print (a)
elif(a[i]>a[i+1]):
a[i], a[i+1] = a[i+1], a[i]
i = i + 1
print(a)
sort(a)
错误代码:
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
File "(File location, you don't need to know....)", line 8, in sort
if(i == b):
UnboundLocalError: local variable 'i' referenced before assignment
我不确定这个错误是什么意思或有什么问题。