3.编写程序,生成包含1000个0到100之间的随机整数,并统计每个元素的出现次数。
时间: 2024-05-03 07:22:11 浏览: 42
一维数组的输出-VB6.0语言____自学课件
```python
import random
# 生成随机整数列表
nums = [random.randint(0, 100) for i in range(1000)]
# 统计元素出现次数
count_dict = {}
for num in nums:
if num in count_dict:
count_dict[num] += 1
else:
count_dict[num] = 1
# 输出每个元素的出现次数
for num, count in count_dict.items():
print("{}: {}".format(num, count))
```
阅读全文