py 5.18
阿新 • • 發佈:2018-05-18
set += AS 開始 imp index dex 5.1 spa
一、遞歸函數
# import sys # sys.setrecursionlimit(10000) # count = 0 # def func(n): # n += 1 # print(n) # func(n) # func(count) # def age(n): # if n == 1: # return 23 # else: # return age(n-1) + 2 # print(age(4)) # l = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72,76,82,83,88]View Code# for i in range(len(l)): # if l[i] == 66: # print(i) # l = [2,3,5,6,8,10]
二、二分查找
# def func(li,aim,start = 0,end =None): # end = len(li) if end == None else end #如果最開始查找,end = len() # min_index = (end - start) //2 + start # if start < end: # if aim > li[min_index]:View Code# return func(li,aim,start = min_index+1,end = end) # elif aim < li[min_index]: # return func(li,aim,start = start,end=min_index) # elif aim == li[min_index]: # return min_index # else: # print(start,end) # return ‘沒有此值‘ # print(func(l,9))
py 5.18