下面这个脚本只是学习并练习用的,请不要“鸡蛋里挑骨头”,呵呵
import random
print("randrange:append ten numbers from 0 to 100 to list1 array:")
list1 = []
for i in range(11):
a = random.randrange(0,100)
list1.append(a)
for i in range(11):
print("list1[%d] = %3d" % (i,list1[i]))
print("randint:append ten numbers from 101 to 200 to list2 array:")
list2 = []
for i in range(11):
b = random.randint(101,200)
list2.append(b)
for i in range(11):
print("list2[%d] = %4d" % (i,list2[i]))
print("uniform.:append ten numbers from 201 to 300 to list array:")
list3 = []
for i in range(11):
c = random.uniform(201,300)
list3.append(c)
for i in range(11):
print("list3[%d] = %10.4f" % (i,list3[i]))
print("random:append ten numbers from () to list array:")
list4 = []
for i in range(11):
d = random.random()
list4.append(d)
for i in range(11):
print("list4[%d] = %20.18f" % (i,list4[i]))
print("choice:append ten numbers from list1 to list array:")
list5 = []
for i in range(11):
c = random.choice(list1)
list5.append(c)
for i in range(11):
print("list5[%d] = %3d" % (i,list5[i]))
for i in range(11):
for j in range(11):
if list1[i] < list1[j]:
list1[i],list1[j] = list1[j],list1[i]
if list2[i] < list2[j]:
list2[i],list2[j] = list2[j],list2[i]
if list3[i] < list3[j]:
list3[i],list3[j] = list3[j],list3[i]
if list4[i] < list4[j]:
list4[i],list4[j] = list4[j],list4[i]
if list5[i] < list5[j]:
list5[i],list5[j] = list5[j],list5[i]
for i in range(11):
print("list1[%d] = %3d" % (i,list1[i]))
for i in range(11):
print("list2[%d] = %4d" % (i,list2[i]))
for i in range(11):
print("list3[%d] = %10.4f" % (i,list3[i]))
for i in range(11):
print("list4[%d] = %20.18f" % (i,list4[i]))
for i in range(11):
print("list5[%d] = %3d" % (i,list5[i]))
print("done5")