用python求斐波那契数列的几种方式

#
# num=input("please input a num:")
# list=[]
# for i in range(0,num):
#     if i ==1 or i ==0:
#         list.append(1)
#     else:
#         list.append(list[i-1]+list[i-2])
# print list
# #
# n = input("please in put a number")
# s=[]
# for i in range(0,n):
#     if i == 1 or i == 0:
#         s.append(1)
#     else:
#         s.append(s[i-1]+s[i-2])
# print s

#
# list = []
# for i in range(0,10):
#     if i == 0 or i == 1:
#         list.append(1)
#     else:
#         list.append(list[i-1]+list[i-2])
# print list
#
# a=0
# b = 1
# while (b<100):
#     print b
#     c = a
#     a = b
#     b =a + c
#
#     list = []



def fun(n):
    list = []
    def test(n):
        if n == 1 or n == 0:
            return 1
        else:
            return test(n-1)+test(n-2)
    for i in range(0,n+1):
        list.append(test(i))
    return list


print fun(10)

 

你可能感兴趣的:(Python)