中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Python 輸出斐波納挈數(shù)列

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
    #coding:utf8    
        
    import time  
    import os  
        
    global_list = []    
      
    def test1(n):  
        if n==1 or n==2:    
            return 1    
        else:    
            return test1(n-1) + test1(n-2)    
             
    def test2(n):    
        global global_list    
        if n==1 or n==2:    
            return 1    
        else:    
            temp = test2(n-1) + test2(n-2)    
            if isinstance(temp,int):    
                global_list.append(temp)    
            return temp    
        
    def main():    
        global global_list    
        input_int = raw_input("Entry your number:")  
        length = int(input_int)  
        #第一種方法  
        start = time.clock()  
        for i in xrange(length):  
            print test1(i+1  
                        ),  
        end = time.clock()  
        print os.linesep + "處理耗時:%f s"%(end-start)  
        #第二種方法  
        start = time.clock()    
        test2(length)    
        temp_set = set(global_list)    
        global_list = [i for i in temp_set]    
        global_list.sort(reverse=True)    
        global_list.extend([1,1])    
        for i in global_list[::-1]:    
            print i,  
        end = time.clock()  
        print os.linesep + "處理耗時:%f s"%(end-start)  
        
    if __name__ == "__main__":    
        main()  

標簽:

版權(quán)申明:本站文章部分自網(wǎng)絡,如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:C#自定義基于Base64的加密解密類

下一篇:C#實現(xiàn)的客戶端彈出消息框封裝類