python 2.7 - Increment list index in a while loop -


i'm trying print first 12 numbers in fibonacci. idea increment 2 list index numbers.

list = [0,1] #sets first 2 numbers in fibonacci sequence added, list append next 10 numbers  listint = list[0] #sets list variable want incremented  list2int = list[1] #set other list variable incremented  while len(list) < 13:       #sets loop stop when has 12 numbers in     x = listint + list2int       #calculates number @ index 2     list.append(x)     #appends new number list     listint += 1    #here supposed incrementing index     list2int +=1 print list 

my output is:

[0, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21] 

i want:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 

please note beginner, , i'm trying without using built in functions. (i'm sure there sort of fibonacci sequence generator).

thanks in advance help!

change first line of while loop:

list = [0,1] #sets first 2 numbers in fibonacci sequence added, list append next 10 numbers  listint = list[0] #sets list variable want incremented  list2int = list[1] #set other list variable incremented  while len(list) < 12:       #sets loop stop when has 12 numbers in     x = list[listint] + list[list2int]       #calculates number @ index 2     list.append(x)     #appends new number list     listint += 1    #here supposed incrementing index     list2int +=1 print list 

also 1st 12 numbers can set while loop condition < 12 because python list indices start 0.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -