#打印斐波那契数列 f0 = 0 f1 = 1 for n in range(2,101): fn = f1 + f0 if fn <= 100: print(fn) f0 = f1 f1 = fn
方法2:
#打印斐波那契数列,100以内 print(0) print(1) a = 0 b = 1 while True: c = a+b if c > 100: break a = b b = c print(c)