From 4ec3fcfc574b460ee4336fb2a9d6892677fa7954 Mon Sep 17 00:00:00 2001 From: d33pster Date: Sun, 14 Apr 2024 18:04:10 +0530 Subject: [PATCH 1/3] issue1 --- main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 2920e9f..e28c688 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,9 @@ from quests import cards from random import randint +import sys def main(): + global result slots = (list(cards.items()), [], []) box_chance_mul = [4, 2, 1] while True: @@ -24,6 +26,8 @@ def main(): print("-" * 4) input("Answer: ") o = input(f"The answer was: {a}\nWere you correct? (Y/n/exit): ") + if o=='y' or o=='Y': + result += 1 print("=" * 5) if not o or o[0].lower() == "y": box_idx = min(box_idx + 1, len(slots) - 1) @@ -39,4 +43,9 @@ def main(): break if __name__ == "__main__": - main() \ No newline at end of file + result = 0 + try: + main() + except KeyboardInterrupt: + print(f'\nYou answered {result} flash cards correctly.') + sys.exit(0) \ No newline at end of file From 231e46b07dce9eea8b4905ea49b241cd33758bde Mon Sep 17 00:00:00 2001 From: d33pster Date: Sun, 14 Apr 2024 18:19:27 +0530 Subject: [PATCH 2/3] fix issue #3 --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index e28c688..5156266 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from quests import cards from random import randint -import sys +import sys, os def main(): global result @@ -20,7 +20,11 @@ def main(): break box = slots[box_idx] q, a = box.pop(n // box_chance_mul[box_idx]) - print(chr(27) + "[2J") + if 'nt' in os.name: + os.system('cls') + else: + os.system('clear') + # print(chr(27) + "[2J") # print(box_idx, f, n) print(q) print("-" * 4) From cb798aeedd59f272a51e02edb2b5e4935c094ef7 Mon Sep 17 00:00:00 2001 From: d33pster Date: Sun, 14 Apr 2024 18:28:46 +0530 Subject: [PATCH 3/3] fix issue #4 --- main.py | 106 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 45 deletions(-) diff --git a/main.py b/main.py index 5156266..d547b2e 100644 --- a/main.py +++ b/main.py @@ -2,54 +2,70 @@ from random import randint import sys, os -def main(): - global result - slots = (list(cards.items()), [], []) - box_chance_mul = [4, 2, 1] - while True: - wts = [len(i) * box_chance_mul[idx] for idx, i in enumerate(slots)] - f = randint(1, sum(wts)) - 1 - box_idx = 0 - a = 0 - n = 0 - for idx, i in enumerate(wts): - a += i - if f < a: - box_idx = idx - n = f - a + i - break - box = slots[box_idx] - q, a = box.pop(n // box_chance_mul[box_idx]) - if 'nt' in os.name: - os.system('cls') - else: - os.system('clear') - # print(chr(27) + "[2J") - # print(box_idx, f, n) - print(q) - print("-" * 4) - input("Answer: ") - o = input(f"The answer was: {a}\nWere you correct? (Y/n/exit): ") - if o=='y' or o=='Y': - result += 1 - print("=" * 5) - if not o or o[0].lower() == "y": - box_idx = min(box_idx + 1, len(slots) - 1) - elif o[0].lower() == "n": - box_idx = max(box_idx - 1, 0) - else: - break - slots[box_idx].append((q, a)) - if len(cards) == len(slots[-1]): - print(f"You have memorised all {len(cards)} cards") - k = input("Exit? (N/y): ") - if o and o[0].lower() == "y": +class leitner: + def __init__(self): + self.result = 0 + self.slots = (list(cards.items()), [], []) + self.box_chance_mul = [4, 2, 1] + + def leitner(self): + while True: + wts = [len(i) * self.box_chance_mul[idx] for idx, i in enumerate(self.slots)] + + f = randint(1, sum(wts)) - 1 + box_idx = 0 + a = 0 + n = 0 + + for idx, i in enumerate(wts): + a += i + if f < a: + box_idx = idx + n = f - a + i + break + + box = self.slots[box_idx] + + q, a = box.pop(n // self.box_chance_mul[box_idx]) + + if 'nt' in os.name: + os.system('cls') + else: + os.system('clear') + + # print question + print(q) + print("-" * 4) + + # ask answer + input("Answer: ") + + o = input(f"The answer was: {a}\nWere you correct? (Y/n/exit): ") + + if o=='y' or o=='Y': + self.result += 1 + + print("=" * 5) + + if not o or o[0].lower() == "y": + box_idx = min(box_idx + 1, len(self.slots) - 1) + elif o[0].lower() == "n": + box_idx = max(box_idx - 1, 0) + else: break + + self.slots[box_idx].append((q, a)) + + if len(cards) == len(self.slots[-1]): + print(f"You have memorised all {len(cards)} cards") + k = input("Exit? (N/y): ") + if o and o[0].lower() == "y": + break if __name__ == "__main__": - result = 0 + leitnerObj = leitner() try: - main() + leitnerObj.leitner() except KeyboardInterrupt: - print(f'\nYou answered {result} flash cards correctly.') + print(f'\nYou answered {leitnerObj.result} cards correctly.') sys.exit(0) \ No newline at end of file