Last answered:

12 Sept 2023

Posted on:

11 Sept 2023

0

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)
print(fibonacci)
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)
Instructor
Posted on:

12 Sept 2023

0

Hey Amazigh,


Thank you for your question!


If you substitute the following line of code

fibonacci = fibonacci.append(number)

with the following

fibonacci.append(number)

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

The reason for this is that the operation

fibonacci.append(number)

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

type(fibonacci.append(6))

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