python自定义函数演示,计算Fibonacci数列
#------------------------------------------------------------------------------
# Name: function.py
# Author: Kevin Harris
# Last Modified: 02/13/04
# Description: This Python script demonstrates how to create a function
# that writes the Fibonacci series up to n.
#------------------------------------------------------------------------------
def fibonacci( n ):
a, b = 0, 1
while b < n:
print( b )
a, b = b, a+b
# Now call the function we just defined...
fibonacci( 2000 )
input( '\n\nPress Enter to exit...' )
输出结果如下:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
