添加知识点对应的题目的算法
Posted chaosliang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了添加知识点对应的题目的算法相关的知识,希望对你有一定的参考价值。
import pandas as pd def input_prob(grade, subject, knowledge, type_p, prob, A, B, C, D, res): grade = int(grade) if grade <= 6: stemp1 = "小学\\" elif grade <= 9: stemp1 = "初中\\" else: stemp1 = "高中\\" stemp2 = "C:\\Users\\lenovo\\Desktop\\数据库\\" pos = stemp2 + stemp1 + subject + ".xlsx" df1 = pd.read_excel(pos, sheet_name="repository", dtype="涉及题目": str) df1.set_index("ID") df2 = pd.read_excel(pos, sheet_name="problems") df2.set_index("ID") index = df2.index[-1] + 1 flag = False for i in df1.index: if df1.at[i, "知识点"] == knowledge: flag = True temp = i if df1["涉及题目"].at[i] == "nan": df1["涉及题目"].at[i] = str(index) else: df1["涉及题目"].at[i] += " " df1["涉及题目"].at[i] += str(index) break if not flag: return [False, "未找到相应知识点"] df2.loc[index] = [index, type_p, prob, A, B, C, D, res, temp, ""] writer = pd.ExcelWriter(pos) df1.to_excel(writer, sheet_name="repository") df2.to_excel(writer, sheet_name="problems") writer.save() return [True, "导入成功"] input_prob("6", "数学", "数与代数", "选择题", "证明费马大定理", 0, 1, 2, 3, "A")
以上是关于添加知识点对应的题目的算法的主要内容,如果未能解决你的问题,请参考以下文章