-2
I’m trying to put the Fibonacci sequence in Python in Vscode, and every time I try to run the following code, the error appears:
line 8, in <module>
Fibonacci[i] = proximo
IndexError: list assignment index out of range
Someone can give me a light on how to fix ?
Fibonacci = [0]*100
anterior = 0
proximo = 1
i = 0
while (i <= 100):
Fibonacci[i] = proximo
proximo = proximo + anterior
anterior = proximo - anterior
i = i + 1
print(Fibonacci)
Fibonacci.append(proximo)
– Augusto Vasques
Remember that in Python lists are dynamic and can increase/decrease size as needed, so you do not need to create the list with 100 artificial values at the beginning, just do so: https://ideone.com/ARLpBG
– hkotsubo