添加知识点对应的题目的算法
2020-12-13 16:34
标签:false 成功 color style led users write 添加 nbsp 添加知识点对应的题目的算法 标签:false 成功 color style led users write 添加 nbsp 原文地址:https://www.cnblogs.com/Chaosliang/p/11621009.htmlimport pandas as pd
def input_prob(grade, subject, knowledge, type_p, prob, A, B, C, D, res):
grade = int(grade)
if grade :
stemp1 = "小学\\"
elif grade :
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")