python----模拟轮盘抽奖游戏

版权声明:https://blog.csdn.net/weixin_42499593 https://blog.csdn.net/weixin_42499593/article/details/89222295

题目:
轮盘分为三部分: 一等奖, 二等奖和三等奖;
轮盘转的时候是随机的,
如果范围在[0,0.08)之间,代表一等奖,
如果范围在[0.08,0.3)之间,代表2等奖,
如果范围在[0.3, 1.0)之间,代表3等奖,

模拟本次活动1000人参加, 模拟游戏时需要准备各等级奖品的个数.

import random

RewardCount = {
    '一等奖':(0,0.08),
    '二等奖':(0.08,0.3),
    '三等奖':(0.3,1.0)
}

def RewardGet():
    num = random.random()
    for k,v in RewardCount.items():
        if v[0] <= num < v[1]:
            return k

ResultPeople = {}

for i in range(1000):
    res = RewardGet()
    if res not in ResultPeople:
        ResultPeople[res] = 1
    else:
        ResultPeople[res] += 1

for k,v in ResultPeople.items():
    print(k,v,'人')

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42499593/article/details/89222295