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)

 

 
 
 
 
 
 
 
 
 
 

相关文章:

  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2021-10-08
  • 2021-04-25
  • 2022-12-23
  • 2021-06-18
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2022-01-18
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案