1st case:
x = 5
def add(n):
x += n
return x
print(add(5))
local variable 'x' referenced before assignment
2nd case:
fi = [0,1,1,2,3,5,8,13,21,34]
def fibonacci(n):
while len(fi) <= n:
fi.append(fi[-1]+fi[-2])
return fi[n]
print(fibonacci(10),fi)
55 [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
both 'x' and 'fi' are outside the functions, why 'x' raise error but 'fi' not?