Try:
for i in range(0,j):
Instead of:
for i in range(0,N[j]):
Since N[j] will access way beyond whats in the list, such as N[80], which doesn't exist. This is why you're getting a IndexError: list index out of range error.
To fix this, you need to apply range() on your outer loop:
for i in range(len(N)):
print(i)
for j in range(0, N[i]):
print(j)
Which only looks at the indexes i of N when applying it to range() in the inner loop, instead of the actual elements, which are a lot larger.
If you want to access whats actually in the list with respect to an index, try this:
N = [20,40,60,80]
for i in range(len(N)):
print(i, "->", N[i])
Which outputs:
0 -> 20
1 -> 40
2 -> 60
3 -> 80
If you want just the numbers:
for number in N:
print(number)
If you want both the index and the number in a more pythonic manner:
for index, number in enumerate(N):
print(index, "->", number)
Which outputs:
0 -> 20
1 -> 40
2 -> 60
3 -> 80
jis value fromN, notindexso you getN[80]butNdoesn't so many elements. - userange(0, j)