酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

python根据题库统计题目的类型和数量,并输出统计结果注:题库在文件夹下,文件名为:python题库(考试用)题库如下第二章 一、选择题 (1)以下input()函数的调用方式中,符合语法的是()。 a. input b. input " " c. input ' ' d. input() (2)设m=a,则 prin(m*3)的输出结果是()。 a. 3*a b. aaa c. mmm d.报错 (3)设m=8,则 print(m *3)的输出结果是()。 a.3*8 b.38 c.888 d.24 (4)设m='a',则 print(m *3)的输出结果是()。 a. 3m b. mmm c.aaa d.3*a (5) 设m="8",则 print(m*3)的输出结果是()。 a.3m b.mmm c.888 d.3*a (6) print(int(3.14))的输出结果是()。 a.3 b.3.1 c.4 d.3.14 (7)以下可以作为标识符的是()。 a. global b. distance c.2

以下是用 Python 实现的代码: ```python import os def count_question_types_and_numbers(folder_path): question_types = {} file_path = os.path.join(folder_path, 'python 题库(考试用)') with open(file_path, 'r') as file: lines = file.readlines() for line in lines: # 去除每行前后的空格和换行符 line = line.strip() if line.startswith('(1)'): # 识别为选择题 if '选择题' in question_types: question_types['选择题'] += 1 else: question_types['选择题'] = 1 for key, value in question_types.items(): print(f"{key}: {value}") folder_path = 'your_folder_path' # 请将这里替换为实际的文件夹路径 count_question_types_and_numbers(folder_path) ``` 额外需要注意的逻辑点: 1. 确保文件夹路径的正确性,否则无法读取到题库文件。 2. 处理文件内容时,要考虑可能存在的格式不一致或异常情况。 3. 统计类型时,要准确判断题目的类型特征,避免误判。 [2024-12-11 13:37:02 | AI写代码神器 | 276点数解答]

相关提问