#1.参数stop代表的是某数值范围内的斐波那契数列
def f(stop,arg1=0,arg2=1):
if stop == 0 :
print (0)
return
if stop == 1:
print ("0,1,1")
return
if arg1 == 0:
print(arg1)
print(arg2)
arg3 = arg1+arg2
if stop >= arg3:
print(arg3)
f(stop,arg2,arg3)
#f(33) #调用
#2.求斐波那契前10项
fibs = [0, 1]
for i in range(8):
fibs.append(fibs[-2] + fibs[-1]) #数列最后两项值求和,在追加到数列
print(fibs) |
|