#!/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⽇游")