模拟轮盘抽奖游戏:模拟游戏需要准备个等级评奖的个数。
作者:互联网
题目:模拟轮盘抽奖游戏:一等奖、二等奖、三等奖轮盘随机转动:一等奖范围【0,0.08】;二等奖范围【0.08,0.3】;三等奖范围【0.3,1】模拟本次活动参加人数自定,模拟游戏需要准备个等级评奖的个数。
import random
award={
'一等奖':(0,0.08),
'二等奖':(0.08,0.3),
'三等奖':(0.3,1)
}
def AwardFunc():
"""用户的得奖等级"""
number = random.random()# 生成一个0~1之间的随机数
for a, b in award.items(): # 判断随机转盘是几等奖
if b[0] <= number < b[1]:
return a
resultAward = {}
c=int(input("Please input number:"))
for i in range(c):
res = AwardFunc()
if res not in resultAward:
resultAward[res] = 1
else:
resultAward[res] += 1
for a, b in resultAward.items():
print(a, ':', b)
标签:0.08,res,0.3,random,模拟游戏,轮盘,评奖,resultAward 来源: https://blog.csdn.net/m0_46303002/article/details/117334806