投掷骰子的游戏,键值对

import random
times=10000
count = {"1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0}

for i in range(0,times):
num=random.choice(list(count.keys()))
#此处注意一定要加list
#num是键
count[num]=count[num]+1
#count是值
for num, counts in count.items():

print('数字{}的概率为{}'.format(num,counts/times))

#items()是键值对

posted @ 2020-07-07 10:49  MINGZHUQI  阅读(148)  评论(0编辑  收藏  举报