斐波纳契数列 |
斐波那契数列指的是这样一个数列 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368........
这个数列从第3项开始,每一项都等于前两项之和。
示例1:
1 def sum(arg1,arg2,stop): 2 arg3 = arg1 + arg2 3 print(arg3,) 4 if arg3 < 10: 5 sum(arg2,arg3,stop) 6 7 sum(0,1,10
输出:
1 2 3 5 8 13
示例2:
a,b = 0,1 while b < 10: print(b,) a,b = b,a+b
输出:
1 1 2 3 5 8
原文地址:https://www.cnblogs.com/bangyongfeng/p/9228231.html
时间: 2024-10-30 11:44:08