1 ''' 2 100 以内的 斐波那契数列: 3 4 ''' 5 # 前两项必须给出,要不没法加减 6 # 因为不知道循环次数,所以用while 循环 7 a = 0 8 b = 1 9 print(b) 10 while True: 11 c = a + b 12 if c > 100: break # 大于100 后 退出循环 13 a = b # a,b = b,c 14 b = c 15 print(c) 16 17 18 ''' 19 求斐波那契数列的第101项 20 ''' 21 22 a = 0 23 b = 1 24 count = 1 25 print(count, b) 26 while True: 27 c = a + b 28 if count == 101: break 29 count += 1 30 a = b # a,b = b,c 31 b = c 32 print(count,c)