年会抽奖小程序

#!/usr/bin/env python 
# -*- coding:utf-8 -*-
# Author:玄铁重剑无锋
# @Author  :   {玄铁重剑无锋}
# @License :   (C) Copyright 2021 玄铁重剑无锋, All rights reserved.
# @Contact :   {sfrexpect@163.com}
# @File    :   02_年会抽奖小程序.py
# @Time    :   2021/8/26 10:23
# @Desc    :
# 年会抽奖程序
# 张三科技有限公司有300员⼯,开年会抽奖,奖项如下:
# ⼀等奖 3名, 泰国5⽇游
# ⼆等奖6名,Iphone⼿机
# 三等奖30名,避孕套⼀盒
# 规则:
# 1. 共抽3次,第⼀次抽3等奖,第2次抽2等奖,第3次压轴抽1等奖
# 2. 每个员⼯限中奖⼀次,不能重复
# 解题思路:
# 1. ⽣成⼀个员⼯列表,⽤random模块从⾥⾯取随机值
# 2. 取完值之后,⽴刻从员⼯⼤列表⾥把中奖⼈删掉,即可防⽌其再次中奖
import random
totle_people = []
for i in range(1,301):
    totle_people.append(f"员工{i}")
print(totle_people)
# print(totle_people)
count = 3
while count > 0:
    if count == 3:
        for i in range(30):
            zhongjiang_30 = "".join(random.sample(totle_people,1))
            # print(three_30)
            totle_people.remove(zhongjiang_30)
            print(f"恭喜{zhongjiang_30}中三等奖,避孕套⼀盒")
        # 验证剩余人数是否正确
        # print(len(totle_people))
    elif count == 2:
        for i in range(6):
            zhongjiang_6 = "".join(random.sample(totle_people, 1))
            totle_people.remove(zhongjiang_6)
            print(f"恭喜{zhongjiang_6}中二等奖,Iphone⼿机一部")
        # print(len(totle_people))
    else:
        for i in range(3):
            zhongjiang_3 = "".join(random.sample(totle_people, 1))
            totle_people.remove(zhongjiang_3)
            print(f"恭喜{zhongjiang_3}中一等奖,泰国5⽇游")
        # print(len(totle_people))
    # 验证剩余次数
    count -= 1
    # print(f"还剩{count}次抽奖")


 

import random
from faker import Faker

# 可以生成随机中文名字
alex = Faker(locale="zh-CN")
totle_people = []
for i in range(1, 301):
    totle_people.append(alex.name())
# print(totle _people)

# 中奖员工列表
level = [30, 6, 3]

for i in range(3):
    winner_list = random.sample(totle_people, level[i])
    # 分别中三二一等奖的人的列表
    # print(winner_list)
    # .center(width[, char]) 返回长度为width的字符串
    # 字符串左右使用尽可能相同的char参数提供的字符填充
    print(f"中{3-i}等将的人员信息------".center(50, "*"))
    for del_winner in winner_list:
        totle_people.remove(del_winner)
        if i == 0:
            print(f"恭喜{del_winner}中{3 - i}等奖, 避孕套⼀盒")
        elif i ==1:
            print(f"恭喜{del_winner}中{3 - i}等奖, Iphone⼿机一部")
        else:
            print(f"恭喜{del_winner}中{3-i}等奖, 泰国5⽇游")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

工具人01

仗剑天涯,从你的打赏开始

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值