标签:ret append 结果 return pen turn 函数 app 算法
斐波那契:
def fei(x,a=1,b=1,i=0,li=None): i+=1 if li == None: li=[1,1] if i == x: a,b = b,a+b li.append(b) return li else: a,b = b,a+b li.append(b) return fei(x,a,b,i,li)
结果:
fei(5) --------------------------- [1, 1, 2, 3, 5, 8, 13] fei(15) --------------------------- [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]
假POW函数:
def cospow(x,n): if n == 1: return x elif n == 0: return 1 elif x == 0: return 0 elif n<0: return 1/(cospow(x,n*-1-1)*x) return cospow(x,n-1)*x
标签:ret append 结果 return pen turn 函数 app 算法
原文地址:https://www.cnblogs.com/GetAlice/p/9418682.html