[Python] python自定义函数演示,计算Fibonacci数列 →→→→→进入此内容的聊天室

来自 , 2021-03-14, 写在 Python, 查看 120 次.
URL http://www.code666.cn/view/749b3dec
  1. #------------------------------------------------------------------------------
  2. #           Name: function.py
  3. #         Author: Kevin Harris
  4. #  Last Modified: 02/13/04
  5. #    Description: This Python script demonstrates how to create a function
  6. #                 that writes the Fibonacci series up to n.
  7. #------------------------------------------------------------------------------
  8.  
  9. def fibonacci( n ):
  10.     a, b = 0, 1
  11.     while b < n:
  12.         print( b )
  13.         a, b = b, a+b
  14.  
  15. # Now call the function we just defined...
  16.  
  17. fibonacci( 2000 )
  18.  
  19. input( '\n\nPress Enter to exit...' )
  20.  
  21.  
  22.  
  23. #//python/8092

回复 "python自定义函数演示,计算Fibonacci数列"

这儿你可以回复上面这条便签

captcha