def fun(n): #斐波那契数列 a=0 b=1 i=1 while(i<=n): c=a+b a=b b=c i+=1 return c for i in range(1,10): print(fun(i),end=',') print(fun(10))
输出结果:1,2,3,5,8,13,21,34,55,89
def fun(n): #斐波那契数列 a=0 b=1 i=1 while(i<=n): c=a+b a=b b=c i+=1 return c for i in range(1,10): print(fun(i),end=' ') print(fun(10))
输出结果:1 2 3 5 8 13 21 34 55 89