当前位置: 移动技术网 > IT编程>脚本编程>Python > 迭代法计算斐波那契数列

迭代法计算斐波那契数列

2019年10月04日  | 移动技术网IT编程  | 我要评论

protel教程,被偷听的女人,军事历史小说

    def f(n):
        second = 1
        result = 1
        while (n>2):
            n-=1
            first = second
            second = result
            result = second +first
        print result
        return result
[f(i) for i in range(16)]
out[15]: [1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]

 

 1    1      1     2    3     5    8

first     second       result

      first            second    result  (n>2)

 

 
 
 
 
 
 
 
 
 
 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网