GPT 只能识别判断题 其它的还是不能排序 GPT代码
[Python] 纯文本查看 复制代码import re
def process_to_strict_format(lines, output_file):
"""Strictly format and sort questions to match the exact user-provided structure."""
single_choice = []
multiple_choice = []
true_false = []
current_question = []
# Classify questions
for line in lines:
stripped_line = line.strip()
# Detect question start (e.g., "1、", "2、")
if re.match(r"^\d+、", stripped_line):
if current_question: # Save the current question
content = "\n".join(current_question)
if "正确答案:" in content:
answer = content.split("正确答案:")[-1].strip()
if len(answer) == 1:
single_choice.append(current_question)
elif len(answer) > 1:
multiple_choice.append(current_question)
elif "正确答案:错误" in content or "正确答案:正确" in content:
true_false.append(current_question)
current_question = []
current_question.append(line)
# Save the last question
if current_question:
content = "\n".join(current_question)
if "正确答案:" in content:
answer = content.split("正确答案:")[-1].strip()
if len(answer) == 1:
single_choice.append(current_question)
elif len(answer) > 1:
multiple_choice.append(current_question)
elif "正确答案:错误" in content or "正确答案:正确" in content:
true_false.append(current_question)
# Write questions into the output file with headings and proper formatting
with open(output_file, 'w', encoding='utf-8') as outfile:
# Write 单选题
outfile.write("单选题\n\n")
question_number = 1
for question in single_choice:
for i, line in enumerate(question):
if i == 0: # Update question number
line = re.sub(r"^\d+、", f"{question_number}、", line)
outfile.write(line)
outfile.write("\n")
question_number += 1
# Write 多选题
outfile.write("多选题\n\n")
for question in multiple_choice:
for i, line in enumerate(question):
if i == 0: # Update question number
line = re.sub(r"^\d+、", f"{question_number}、", line)
outfile.write(line)
outfile.write("\n")
question_number += 1
# Write 判断题
outfile.write("判断题\n\n")
for question in true_false:
for i, line in enumerate(question):
if i == 0: # Update question number
line = re.sub(r"^\d+、", f"{question_number}、", line)
outfile.write(line)
outfile.write("\n")
question_number += 1
# Input and output paths
input_path = "huawei_reordered.txt" # Replace with your input file path
strict_format_output_path = "huawei_strict_format_output.txt" # Replace with desired output file path
# Read the input file and process
with open(input_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
process_to_strict_format(lines, strict_format_output_path)
源代码 下载
[color=]https://wwij.lanzout.com/iKuMf2g2v3za
[color=]这个类型全部在一起 判断题在一起
正确
错误
回答正确考生得分:5分
正确答案:错误
答案解析:
无
[color=]这个类型 单选题目在一起
A.
预约后48小时内
B.
以购买界面显示信息为准
C.均为11月19日发货
回答正确考生得分:5分
正确答案:B
答案解析:
无
[color=]这个类型在一起 多选题在一起
A.您好
B.您好
C.如商品
回答错误考生得分:0分
正确答案:AC
答案解析:
无