python求斐波那契数列示例分享
程序员文章站
2023-11-26 13:50:52
复制代码 代码如下:def getfibonacci(num): res=[0,1] a=0 b=1 for x in range(...
复制代码 代码如下:
def getfibonacci(num):
res=[0,1]
a=0
b=1
for x in range(0,num):
if x==a+b:
res.append(x)
a,b=b,a+b
return res
res=getfibonacci(1000)
print(res)
#递归
a=[0,1]
qian=0
def fibna(num,qian):
print(num)
he=num+qian
if he<1000:
a.append(he)
qian=num
fibna(he,qian)
fibna(1,0)
print(a)
下一篇: python转换摩斯密码示例