`import random
prizes = [‘A Prize’, ‘B Prize’, ‘C Prize’]
participants = [‘Alice’, ‘Bob’, ‘Charlie’, ‘Dave’, ‘Eve’]
max_attempts = 3
attempts = {}
for participant in participants:
attempts[participant] = 0
while len(prizes) > 0:
# 随机抽取一名参与者
participant = random.choice(participants)
# 如果该参与者已经达到了最大抽奖次数,就跳过
if attempts[participant] >= max_attempts:
continue
# 否则,随机抽取一件奖品
prize = random.choice(prizes)
# 把奖品从列表中删除
prizes.remove(prize)
# 打印获奖信息
print(f'{participant} won {prize}!')
# 增加该参与者的抽奖次数
attempts[participant] += 1
`@Python 晚会抽奖程序