斐波那契数列,100以内
斐波那契数列:1,1,2,3,5,6,13,21,34,55,89,144…
如果设F(n)为该数列的第n项( n 属于N*),那么这句话可以写成:F(n) = F(n-1)+F(n-2)
F(0)=0,F(1)=1,F(n) = F(n-1)+F(n-2)
# 斐波那契数列:F(0)=0,F(1)=1,F(n)=F(n-1)+F(n-2)
lists = [1]
upnum = 1 # n-1数值
upupnum = 0 # n-2的数值
for i in range(1, 101):
num = upupnum + upnum
lists.append(num)
upupnum = upnum
upnum = num
print(lists)
# 方法二:
a = 1
b = 1
print(a)
while b < 100:
print(b)
a, b = b, a + b