This code doesn't work.
error says:
UnboundLocalError: local variable 'on' referenced before assignment
arr = []
for i in range(4):
arr.append([0 for t in range(4)])
on=1
num_r = 0
def go_r(d):
for i in range(d):
arr[num_r][i+num_r] = on
on +=1
return arr
print(go_r(4))
but this code(↓) works.
arr = []
for i in range(4):
arr.append([0 for t in range(4)])
on=1
num_r = 0
def go_r(d):
for i in range(d):
arr[num_r][i+num_r] = on
return arr
print(go_r(4))
Difference between two codes is the upper code includes "on +=1"
I want my code to print [[1, 2, 3, 4], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]].
So I insert "on +=1" in upper code.
What should I do? I don't know what's the problem on the upper code.