Last answered:

12 Sept 2023

Posted on:

11 Sept 2023


Resolved: question 7 fibonacci series

i tried this code for the fibonacci series:

fibonacci =[0, 1]
length = int(input('enter the length of the series '))
for i in range(0,length-2):
    number = fibonacci[i] + fibonacci[i+1]
    fibonacci = fibonacci.append(number)
and it doesn't work. this error pops out 

TypeError: 'NoneType' object is not subscriptable   

Can anyone tell me please :

-what does it mean ?

 -how to/can we fix it,

1 answers ( 1 marked as helpful)
Posted on:

12 Sept 2023


Hey Amazigh,

Thank you for your question!

If you substitute the following line of code

fibonacci = fibonacci.append(number)

with the following


, i.e., remove fibonacci = , your code will execute smoothly.

The reason for this is that the operation


returns a NoneType. You can convince yourself of that by executing, for example, the following


You will see that it returns a NoneType. Therefore, your original code assigns NoteType to the fibonacci variable which means fibonacci is no longer a list.

Kind regards,

365 Hristina

Submit an answer