斐波那契数列(Fibonacci sequence),又称黄金分割数列,因数学家列昂纳多·斐波那契(Leonardoda Fibonacci)以兔子繁殖为例子而引入,故又称为“兔子数列”。在数学上,斐波那契数列定义如下:
实现代码如下:
#e1.3 Fibonacci_Sequence
#coding = utf8
"""书上正常内容"""
a,b=0,1
while a<1000:
print(a,end='、')
a,b=b,a+b
print()
"""改进版,最后输出句号"""
a,b=0,1
print(a,end='')
while b<1000:
print('、'+str(b),end='')
a,b=b,a+b
print('。')
#、号和数字之间没有空格
a,b=0,1
print(a,end='')
while b<1000:
print('、',b,end='')
a,b=b,a+b
print('。')
#、号和数字之间有空格