这个
rth
斐波那契的术语是
r-1th
术语+
r-2th
术语,其中r>0
所以你可以从一个初始列表开始
[0,1]
然后使用for循环遍历具有最大限制的自然数
n
和最小极限
1
然后使用列表中的索引来获取
r-1th
术语和
r-2
然后附加
rth
在名单上。我会这样做的。
intialise the list with elements 0,1
use a for loop here to loop through the natural numbers
get the r-1th from the list
get the r-2th from the list
add both
append the result you got, in the list you initialised