递归...
def age(n):
if n == 1:
return 18
else:
return age(n-1)+2 # 反复调用函数age()
print(age(4))
l = [1,3,5,7,9,11]
def two_search(li,aim,start = 0,end = None):
end = len(li)-1 if end is None else end
mid_index = (end - start) // 2 + start
if start <= end:
if li[mid_index] > aim:
return two_search(li,aim,start = 0 ,end = mid_index-1)
elif li[mid_index] < aim:
return two_search(li,aim,start = mid_index+1,end = end)
elif li[mid_index] == aim:
return mid_index
else:return '无此值'
else:return '无此值'
print(two_search(l,7)) # 3