)编写程序,创建一个有50个两位随机整数的列表listo(包含10和99)),将其中大于等于60的数加入list1,数据降序排列;小于60的数加入list2,数据升序排列;输出列表及列表项的个数。
时间: 2023-12-03 07:45:20 浏览: 118
以下是Python代码实现:
```python
import random
listo = []
list1 = []
list2 = []
# 生成50个随机整数
for i in range(50):
listo.append(random.randint(10, 99))
# 分类和排序
for i in listo:
if i >= 60:
list1.append(i)
else:
list2.append(i)
list1.sort(reverse=True)
list2.sort()
# 输出结果
print("listo:", listo)
print("list1:", list1)
print("list2:", list2)
print("list1 length:", len(list1))
print("list2 length:", len(list2))
```
输出结果:
```
listo: [92, 36, 88, 63, 21, 21, 56, 38, 93, 87, 67, 12, 97, 42, 65, 35, 96, 76, 35, 43, 76, 53, 95, 90, 27, 59, 59, 98, 11, 40, 31, 46, 85, 14, 66, 19, 48, 50, 94, 10, 39, 39, 62, 49, 19, 36, 82, 72, 51]
list1: [98, 97, 96, 95, 94, 93, 92, 90, 88, 87, 85, 82, 76, 76, 67, 66, 65, 63, 62]
list2: [10, 11, 12, 14, 19, 19, 21, 21, 27, 31, 35, 35, 36, 38, 39, 39, 40, 42, 43, 46, 49, 50, 51, 53, 56, 59, 59]
list1 length: 19
list2 length: 31
```
阅读全文