以下是用 Python 实现的代码示例: ```python import os def count_questions(file_path): # 初始化各个类型题目的计数器 choice_count = 0 judge_count = 0 with open(file_path, 'r', encoding='utf-8') as file: lines = file.readlines() for line in lines: if '选择题' in line: choice_count += 1 elif '判断题' in line: judge_count += 1 # 输出统计结果 print(f"第二章:选择题{choice_count}道,判断题{judge_count}道") # 替换为您的实际文件路径 file_path = '/data/share_files/experiment_file/e_16545/datafiles/python 题库(考试用)' count_questions(file_path) ``` 额外需要注意的逻辑点: 1. 要确保文件路径的正确性,否则可能无法读取到题库文件。 2. 对于题目的类型判断逻辑要准确,以避免统计错误。 3. 考虑处理文件可能不存在或者无法读取的异常情况。 [2024-12-11 13:44:25 | AI写代码神器 | 251点数解答]