已经各商品中奖概率,求根据中奖概率进行中奖显示

import random
list_more = list(range(1,101))
#一等奖 10%
list_1 = random.sample(list_more,10)
#二等奖 20%
list_2 = random.sample(list(set(list_more)-set(list_1)),20)
#三等奖 30%
list_3 = random.sample(list(set(list_more)-set(list_1)-set(list_2)),30)
#四等奖 40%
list_4 = random.sample(list(set(list_more)-set(list_1)-set(list_2)-set(list_3)),40)
print list_1,len(list_1)
print list_2,len(list_2)
print list_3,len(list_3)
print list_4,len(list_4)
a = raw_input("开始抽奖:(Y/N)"  )
if a.lower() == "y":
    x = random.randint(1,100)
    print x
    if x in list_1:
        print ("恭喜一等奖")
    elif x in list_2:
        print ("恭喜二等奖")
    elif x in list_3:
        print ("恭喜三等奖")
    else:
        print ("恭喜四等奖")

这样保证每一次进行抽奖前,奖池中对应的个的中奖池号码是随机生成的,提高了逻辑的严谨性

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值