数据统计类型:字典描述
import random
random.seed(10) # 设置随机种子
a, b = map(int, input().split()) # 输入区间端点
count = {} # 统计数字出现次数的字典
for i in range(100): num = random.randint(a, b) # 生成随机数 if num not in count: count[num] = 1 else: count[num] += 1
for num in sorted(count.keys()): # 按数字从小到大排序 if count[num] != 0: # 只输出出现次数不为0的数字 print(num, count[num])
原文地址: https://www.cveoy.top/t/topic/hnud 著作权归作者所有。请勿转载和采集!