Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #4 #58

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 65 additions & 36 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,71 @@
from quests import cards
from random import randint
import sys, os

def main():
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])
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): ")
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__":
main()
leitnerObj = leitner()
try:
leitnerObj.leitner()
except KeyboardInterrupt:
print(f'\nYou answered {leitnerObj.result} cards correctly.')
sys.exit(0)