Python 输出斐波纳挈数列


#!/usr/bin/env python
#coding:utf8

import time

global_list = []

def test(n):
    global global_list
    if n==1 or n==2:
        return 1
    else:
        temp = test(n-1) + test(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)
    test(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,


if __name__ == "__main__":
    main()

 

\

相关内容

    暂无相关文章

评论关闭