降序排列表
每次的执行均会得到一个最小
list=[199, 96, 108, 98, 188, 84, 166, 1, 113, 106, 87, 93, 39, 154, 146, 154, 27, 44, 96, 37, 174, 127, 131, 79, 181, 115, 195, 133, 132, 81, 169, 17, 114, 29, 50, 128, 156, 199, 132, 180, 85, 194, 37, 5, 195, 139, 108, 26, 178, 107, list= [31, 79, 152, 7, 64, 197, 66, 101, 30, 38, 2, 51, 144, 135, 47, 179, 14, 23, 75, 6, 181, 20, 183, 22, 75, 130, 71, 28, 119, 43, 114, 180, 4, 102, 109, 12, 110, 58, 69, 173, 66, 185, 43, 3, 11, 151, 41, 145, 166, 121]
for i in range(1, len(list)):
for j in range(len(list)-i):
if list[j]<list[j+1]:
a=list[j]
list[j]=list[j+1]
list[j+1]=a
print(list)
菱形的打印及倒三角的打印
每行的符号数1 3 5 7 9 7 5 3 1(可分段实现 先上面)
for i in range(5):
print(' '*(5-i),'*'*(2*i+1))
for i in range(6):
print(' '*i,'*'*(2*(6-i)-1))
倒三角形
for i in range(1,24):
print(' '*(i),'*'*((23-i)*2+1),' '*(i))
倍数的分类——append的用法
3的倍数 5的倍数 3和5共同的倍数
list1=[]
list2=[]
list3=[]
for i in range(1,101):
if i%3==0 and i%5==0:
list3.append(i)
if i%3==0:
list1.append(i)
if i%5==0:
list2.append(i)
print(list1)
print(list2)
print(list3)
将美好碎片变小,装进CSDN
|