Python and Math

来自开放百科 - 灰狐
跳转到: 导航, 搜索

Fibonacci

>>> def fib(n):    # write Fibonacci series up to n
...     """Print a Fibonacci series up to n."""
...     a, b = 0, 1
...     while b < n:
...         print b,
...         a, b = b, a+b
... 
>>> # Now call the function we just defined:
... fib(2000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597
分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱