1
我試圖構建一個可以追加值,空單
n1 = 1
n2 = 2
fn = []
功能我想同時添加n1和n2,然後將該值發送給fn。
然後我想重新分配n1和n2到序列的最後兩個值。
然後我希望能夠在一定量的迭代後停下來。
我基本上是試圖構建一個斐波那契序列發生器,而無需使用功能
#s(n) = (1.618^n-(1-1.618)^n)/(5^.5)`
例子:
fn = []
def fibb(n1,n2,f_iter):
# n1 would be the first number of the sequence
# n2 would be the second number of the sequence
# f_iter would be how many iterations it would do until finished
因此,如果輸入的是:
def fibb(1,2,10):
return fn
fn = [1,2,3,5,8,13,21,34,55,89,144,233]
#f_iter(0:1+2=3,1:2+3=5,2:3+5=8,3:5+8=13, . . . 10:89+144=233)
我看到問題,但沒有嘗試過。 –
查看http://stackoverflow.com/questions/3953749/python-fibonacci-generator?rq=1 –
斐波那契實現通常是Python教程中使用的第一個示例之一。 –