用python写一个随机点名系统
时间: 2023-11-07 07:05:04 浏览: 97
以下是一个简单的随机点名系统的Python代码:
```python
import random
students = ["小明", "小红", "小张", "小李", "小王"]
while True:
input("请按Enter随机点名:")
print(random.choice(students))
```
首先,我们定义了一个名为“students”的列表,其中包含要点名的学生的名字。然后,我们使用Python的内置“random”模块中的“choice”函数来随机选择一个学生。最后,我们使用一个无限循环,每次按下Enter键时,就会随机选择一个学生并将其打印出来。
相关问题
用python写一个随机点名程序
您好,我是C知道,可以回答您的问题。以下是用Python编写随机点名程序的示例代码:
import random
students = ['张三', '李四', '王五', '赵六', '钱七']
random_student = random.choice(students)
print('本次随机点名的学生是:', random_student)
希望对您有所帮助。
用python写一个随机点名的程序
好的,以下是用 Python 编写的一个随机点名的程序:
```python
import random
students = ['小明', '小红', '小华', '小王', '小李']
random_student = random.choice(students)
print('本次被点名的学生是:', random_student)
```
每次运行该程序,都会随机选择一个学生作为被点名的对象。希望您能够喜欢!