#从大到小排列
num = [12, 35, 99, 18, 76] len_num=len(num)-1 for i in list(range(len_num)):#控制循环的次数 for j in list(range(len_num-i)): if num[j]<num[j+1]: num[j],num[j+1]=num[j+1],num[j] print(num)
#从大到小排列
num = [12, 35, 99, 18, 76] len_num=len(num)-1 for i in list(range(len_num)):#控制循环的次数 for j in list(range(len_num-i)): if num[j]<num[j+1]: num[j],num[j+1]=num[j+1],num[j] print(num)