# Fibonacci series
def fib(n):
a,b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a + b
print()
fib(1000)
使用生成器实现斐波那契数列
def fibo(n):
a, b = 0, 1
while b < n:
a, b = b, a+b
yield a
# Fibonacci series
def fib(n):
a,b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a + b
print()
fib(1000)
使用生成器实现斐波那契数列
def fibo(n):
a, b = 0, 1
while b < n:
a, b = b, a+b
yield a
本文标题:斐波那契数列
本文链接:https://www.haomeiwen.com/subject/xpdmbhtx.html
网友评论