Continuous division - Indexerror: list index out of range

Asked

Viewed 77 times

0

for i in lista:
    lista.append(X)
    X = X * 0.5

for i in range(100):
    print 'N[%d] = %.4f' %(i, lista[i])

This mistake always happens: Indexerror: list index out of range

  • You are trying to access an index that does not exist in the variable lista.

  • The list and the variable "X"

  • You can edit the question and ask if you want.

  • That’s because the variable lista does not have 100 elements... experimente do print len(lista) before the last cycle is to see how many items there are. Anyway to do what you are doing could be more straightforward if you did it soon for i in lista: ... where i will be each element that this list contains

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.