def getRandomQuestion(path, clear): questionList = readJsonFile(path[0]) while True: flag = random.randint(0, len(questionList) - 1) isWrong = question(questionList[flag], flag, len(questionList), clear) if isWrong: saveError(path[2], questionList[flag])
def getOrderQuestion(path, clear): questionList = readJsonFile(path[0]) # flag为当前做题进度 flag = int(readFile(path[1])) while flag < len(questionList): i = questionList[flag] isWrong = question(i, flag, len(questionList), clear) if isWrong: saveError(path[2], i) flag = flag + 1 saveFile(path[1], flag) os.system(clear) empty = input('当前题库已刷完,是否清空进度以便二刷?(y/n)\n') if empty == 'y': flag = 0 saveFile(path[1], flag)
def getError(path, clear): questionList = readJsonFile(path[2]) if len(questionList) == 0: print('错题本为空!正在退出...') return count = 0 # 拷贝questionList的初始长度 length = len(questionList) for item in questionList[:]: isWrong = question(item, count, length, clear) if isWrong == False: # 第一次即做对判定为已经掌握 questionList.remove(item) # 实时更新 saveJsonFile(path[2], questionList) count = count + 1 os.system(clear) print('错题本已刷完,已掌握的题目(一次答对的题目)已自动去除!\n正在退出...')
def getExam(path, clear): # 模拟考试(40道单选,10道多选) questionList = readJsonFile(path[0]) examList = [] while len(examList) < 40: flag = random.randint(0, len(questionList) - 1) if len(questionList[flag]['Answer']) == 1: examList.append(questionList[flag]) while len(examList) < 50: flag = random.randint(0, len(questionList) - 1) if len(questionList[flag]['Answer']) > 1: examList.append(questionList[flag]) count = 0 for item in examList: isWrong = question(item, count, len(examList), clear) if isWrong: saveError(path[2], item) count = count + 1 os.system(clear) print('考试结束,退出程序...')
def saveError(path, item): # 用于添加题目到错题本 questionList = readJsonFile(path) if item not in questionList: questionList.append(item) saveJsonFile(path, questionList)