# 斐波那契数列模块
"""
#方法一:从最大值考虑,打印前n位的数字
"""
def fib(numMax):
a, b = 0, 1
while b < numMax:
print(b, end=' ')
a, b = b, a+b
print()
#二从位数考虑,打印第n位的数字
#方法一:
def fiboTwo(num):
list1 = []
for i in range(num):
if i<= 1:
list1.append(1)
else:
list1.append(list1[-2]+list1[-1])
return list1[-1]
#方法二:
def fiboTwo1(num):
a,b = 1,1
for i in range(num-1):
a,b = b,a+b
return a
斐波那契数列python实现
最新推荐文章于 2023-12-12 20:05:20 发布