立即学习:https://edu.csdn.net/course/play/24459/296342?utm_source=blogtoedu
递归函数
def calc(n): print(n) n = int(n/2) if n>0: calc(n) calc(100)
练习:
a = [1,3,4,6,7,8,9,11,15,17,19,21,22,25,29,33,38,69,107] def fd(n,l): m = l[int(l.index(l[-1])/2)] if n == m or n == l[0] or n == l[-1]: print("in the list") elif n < m and l.index(l[-1])>1: l = l[0:l.index(m)+1] fd(n,l) elif n > m and l.index(l[-1])>1: l = l[l.index(m):] fd(n,l) else: print("not in the list") fd(69,a)