码迷,mamicode.com
首页 > 其他好文 > 详细

py 5.18

时间:2018-05-18 20:38:59      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:pen   分享图片   count   close   isp   port   func   opened   src   

一、递归函数

技术分享图片
# 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]
# for i in range(len(l)):
#     if l[i] == 66:
#         print(i)
# l = [2,3,5,6,8,10]
View Code

二、二分查找

技术分享图片
# 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]:
#             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))
View Code

 

py 5.18

标签:pen   分享图片   count   close   isp   port   func   opened   src   

原文地址:https://www.cnblogs.com/liujjpeipei/p/9057862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!