def record(self, question, correct, time, persist=True): for child in recursive_children(question): self.feed.mark(child.q) if self.stack_failure(question): while self.stack: stack_question, failed_before = self.stack.pop() if failed_before: self.record_simple(stack_question.q, False, time) else: for child in recursive_children(stack_question): self.record_simple(child.q, False, time) would_get_second_chance = self.second_chance(question) if self.stack: self.stack.pop() if would_get_second_chance: if correct: for child in recursive_children(question): self.record_simple(child.q, True, time) else: self.stack.append((question, True)) for child in reversed(question.children): self.stack.append((child, False)) else: self.record_simple(question.q, correct, time) if persist: self.persist.record(question, correct, time) return correct
def main(): load() print("Welcome to the Quiz program (2.0)") print("Review Queue:", pack.triage.get_review_queue_size(time.time())) try: input("Press enter to begin.") except KeyboardInterrupt: print("Stopped.") return start = time.time() with pack: try: while True: try: current_time = time.time() question = pack.get_question(current_time) for child in recursive_children(question): if child.q not in pack.feed.seen: print("New Question:") print(child.body) print(question.prompt) ans = "" while ans == "": ans = input() correct = question.check(ans) if correct: print("Correct!") else: print("### Incorrect ###") if not pack.second_chance(question): print("Remember:") print(question.body) pack.record(question, correct, current_time) except StopIteration as e: print("Out of cards in:", e.value) break except KeyboardInterrupt: print("Finished.") end = time.time() dt = end - start total, wrong, new = pack.stats() print("You learned %d new problems." % new) print("You missed %d problems." % wrong) print("You answered %d problems in %d minutes %d seconds." %\ (total, dt // 60, dt % 60)) if total > 0: print("That is %.3f seconds per problem, or %.3f problems per minute"%\ (dt / total, 60 * total / dt)) print("Your accuracy was %d%%, or %s:1 right:wrong" %\ (100*float(total-wrong)/total, ("%.1f"%(float(total-wrong)/wrong)) if wrong > 0 else "inf")) save(pack)