pytho查找斐波那契序列中的值

'''
实现斐波那契序列,查找其中第N个数的值

'''

def  FeiBSequence(list,N):
    length=len(list);
    i=0;
    while i<length:
        if N<=2 and N>0:
            return list[N-1];
            break;
        else:
            z=list[i]+list[i+1];
            list.append(z);
            i+=1;
            length+=1;
            if length==N:
                print list;
                return list[N-1];                
                break;
if __name__ == '__main__':
    print FeiBSequence([1,3],5);
    

 

posted @ 2017-01-19 20:25  浮尘~若梦  阅读(177)  评论(0编辑  收藏  举报