用python编写随机抽奖程序。要求可以更改人员名单和奖品清单
时间: 2023-03-09 10:08:58 浏览: 119
超市购物小票随机抽奖程序python
很高兴为您服务!这是关于用Python编写随机抽奖程序的简单示例代码:import randomdef draw():# 列出人员名单names = ['张三', '李四', '王五', '赵六']# 列出奖品prizes = ['iPhone', 'iPad', 'MacBook', 'iPod']# 随机抽取一个人员winner = random.choice(names)# 随机抽取一个奖品prize = random.choice(prizes)# 返回抽奖结果return winner, prizeif __name__ == '__main__': winner, prize = draw() print('恭喜{}获得了{}!'.format(winner, prize))
阅读全文