這裏只說一下簡單的循環打印,遞歸以後再說。code
a = 0 b = 1 print(a) print(b) while True: c = a + b if c > 100: break a = b b = c print(c)
0 1 1 2 3 5 8 13 21 34 55 89
a = 0 b = 1 # 手動打印前兩項 print('{},{}'.format(0, a)) print('{},{}'.format(1, b)) index = 1 while True: c = a + b a = b b = c index += 1 print('{},{}'.format(index, c)) if index == 101: break
0,0 1,1 2,1 3,2 4,3 5,5 6,8 7,13 8,21 9,34 ... 95,31940434634990099905 96,51680708854858323072 97,83621143489848422977 98,135301852344706746049 99,218922995834555169026 100,354224848179261915075 101,573147844013817084101