It seems that many get this error but each situation is different.
My code:
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)
Error Code:
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
I am not sure what this error means or what is wrong.