功能代码

l=[1,3,5,8,12,34,45,56,67,78,89,123,234,345,456,566,789]
def find(find_num,l):
    print(l)
    if len(l)==0:
        print('not find')
        return
    mid_index=len(l)//2
    if find_num>l[mid_index]:
        l=l[mid_index+1:]
        find(find_num,l)
    elif find_num<l[mid_index]:
        l=l[:mid_index]
        find(find_num,l)
    else:
        print('find it')
find(45,l)
View 二分法
 1 def grogress_bar(percent,width):
 2     if percent > 1:percent=1
 3     show_str=('%%-%ds' %width) %(int(percent * width) *'#')
 4     print('\r%s%% %s' %(int(percent*100),show_str),end='')
 5 
 6 total_size=123451
 7 recv_size=0
 8 while total_size > recv_size:
 9     time.sleep(0.2)
10     recv_size+=1024
11     percent=recv_size/total_size
12     grogress_bar(percent,width=40)
View Code 进度条
def hatted_code(n):
    res=''
    for i in range(n):
        num=str(random.randint(0,9))
        alp=chr(random.randint(65,90))
        res+=random.choice([num,alp])
    return res
print(hatted_code(4))
View Code 随机码

猜你喜欢

转载自www.cnblogs.com/rongge95500/p/9238921.html