1. 程式人生 > >斐波那契數列

斐波那契數列

python 練習

def bona():
    while True:
        n = (input(‘你想打印幾個數的斐波那契數列:‘))
        if not n.isdigit():
            exit()
        a,b,m = 0,1,0
        n = int(n)
        A = ‘‘
        while m < n:
            a,b = b,a+b
            m += 1
            A = ‘‘‘%s  %s‘‘‘ %(A,str(a))
        else:
            print(A)
bona()


本文出自 “ProgressEveryd” 博客,請務必保留此出處http://987774031.blog.51cto.com/11704329/1942054

斐波那契數列