输入“导入k1道题的试卷”,从 question_list.txt 文件中读取k1道题。题 目格式见 question_list.txt 3) 输入“生成k2份答卷”,随机生成k2份选手的答卷,并将结果输出到 文件中,每行格式为: ,之间用逗号分隔,例如“22302023190, 张三, 2023/4/21 21:50:50,A, B, C, ..., C, A”。交卷时间的格式不限,合理即可 A. 学号为11位数字,前两位在[18, 22]范围内,学号不能重复 B. 姓名随机生成,中英文都可以
时间: 2023-12-06 18:39:52 浏览: 146
好的,这是一个简单的Python程序,可以实现你所说的功能:
```python
import random
# 读取题目列表
with open('question_list.txt', 'r', encoding='utf-8') as f:
question_list = [line.strip() for line in f.readlines()]
# 生成学生列表
student_list = []
for i in range(100):
student_id = random.randint(1800000000, 2200000000)
while student_id in [student[0] for student in student_list]:
student_id = random.randint(1800000000, 2200000000)
student_name = ''.join(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ汉字', random.randint(2, 5)))
student_list.append((student_id, student_name))
# 生成答卷列表
answer_list = []
for i in range(10):
student_id, student_name = random.choice(student_list)
answer_time = f'2021/4/{random.randint(1, 30)} {random.randint(0, 23)}:{random.randint(0, 59)}:{random.randint(0, 59)}'
answer_list.append((student_id, student_name, answer_time, *[random.choice(['A', 'B', 'C', 'D']) for j in range(len(question_list))]))
# 输出答卷列表到文件
with open('answer_list.txt', 'w', encoding='utf-8') as f:
for answer in answer_list:
f.write(f'{answer[0]},{answer[1]},{answer[2]},{",".join(answer[3:])}\n')
```
你可以将代码保存为一个名为`generate_test.py`的文件,然后在命令行中运行:
```
python generate_test.py
```
程序会生成一个名为`answer_list.txt`的文件,里面包含了随机生成的10份答卷。
阅读全文