a = int(input("需要多少项"))
def fbna1(n):
a,b=0,1
i = 0
while i < n:
a,b=b,a+b
yield a
i += 1
fb = fbna1(a)
print("fb",fb)
for i in fb:
print(i)
一下为运行测试:
需要多少项
10
fb <generator object fbna1 at 0x000002680214D930>
1
1
2
3
5
8
13
21
34
55
Process finished with exit code 0