投掷骰子的游戏,键值对
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()是键值对