有没有更复杂的Python 随机点名程序
时间: 2023-07-26 15:03:26 浏览: 77
当然有,以下是一个稍微复杂一点的Python随机点名程序:
```python
import random
students = ["Alice", "Bob", "Charlie", "David", "Emily", "Frank", "Gina", "Henry", "Isabel", "Jack"]
num_winners = int(input("How many winners do you want to select? "))
winners = random.sample(students, num_winners)
print("The winners are: ")
for i in range(num_winners):
print(winners[i])
```
这个程序首先定义了一个学生名单列表,然后让用户输入要选择的获奖者数量。接着使用`random.sample()`函数从学生名单中随机选择指定数量的获奖者,并将结果存储在一个名为`winners`的列表中。最后,程序使用一个`for`循环遍历`winners`列表并输出所有获奖者的名字。
阅读全文