Bootstrap

实用:Python3计算斐波那契数列前100项分别是多少?

old1=1
old2=1
n = 100
print("(No.1:  %d) "%old1,end='')
for i in range(n-1):
    old1,old2=old2,old1+old2
    print("(No.%d:  %d) "% (i+2,old1),end='')

运行结果:

(No.1:  1) (No.2:  1) (No.3:  2) (No.4:  3) (No.5:  5) (No.6:  8) (No.7:  13) (No.8:  21) (No.9:  34) (No.10:  55) (No.11:  89) (No.12:  144) (No.13:  233) (No.14:  377) (No.15:  610) (No.16:  987) (No.17:  1597) (No.18:  2584) (No.19:  4181) (No.20:  6765) (No.21:  10946) (No.22:  17711) (No.23:  28657) (No.24:  46368) (No.25:  75025) (No.26:  121393) (No.27:  196418) (No.28:  317811) (No.29:  514229) (No.30:  832040) (No.31:  1346269) (No.32:  2178309) (No.33:  3524578) (No.34:  5702887) (No.35:  9227465) (No.36:  14930352) (No.37:  24157817) (No.38:  39088169) (No.39:  63245986) (No.40:  102334155) (No.41:  165580141) (No.42:  267914296) (No.43:  433494437) (No.44:  701408733) (No.45:  1134903170) (No.46:  1836311
;