写法一:
import random
lucky_num = []
lucky_count = 0
for time in range(0, 3):
lucky_count = 0
print(f'第一次抽奖现在开始,这次抽的是{3-time}等奖\n')
if time == 0:
reward = "三斤苹果"
elif time == 1:
reward = "iPhone14手机"
else:
reward = "泰国5日游 + 手术费报销"
if time == 0:
while True:
lucky = random.randint(1, 301)
if lucky not in lucky_num:
lucky_num.append(lucky)
lucky_count = lucky_count + 1
print(f"{lucky_count}. 恭喜{lucky}号抽中{3-time}等奖,获得{reward}奖励")
if lucky_count == 30:
print("----------------------------------------------------------")
break
elif time == 1:
while True:
lucky = random.randint(1, 301)
if lucky not in lucky_num:
lucky_num.append(lucky)
lucky_count = lucky_count + 1
print(f"{lucky_count}. 恭喜{lucky}号抽中{3 - time}等奖,获得{reward}奖励")
if lucky_count == 6:
print("----------------------------------------------------------")
break
elif time == 2:
while True:
lucky = random.randint(1, 301)
if lucky not in lucky_num:
lucky_num.append(lucky)
lucky_count = lucky_count + 1
print(f"{lucky_count}. 恭喜{lucky}号抽中{3 - time}等奖,获得{reward}奖励")
if lucky_count == 3:
print("----------------------------------------------------------")
break
写法二:
import random
staff_list = []
for i in range(1, 301):
staff_list.append(f"员工{i}")
level = [30, 6, 3]
for j in range(3):
winner_list = random.sample(staff_list, k=level[j])
for winner in winner_list:
staff_list.remove(winner)
print(f"恭喜获得{3 - j}等奖的是:{winner_list}")