-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (45 loc) · 1.4 KB
/
main.py
File metadata and controls
59 lines (45 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import sys
import csv
from time import sleep
from random import choice, shuffle
HERE = os.path.dirname(os.path.abspath(__file__))
cols = ["infinitive", "past simple", "past participle", "pl"]
def shuffled(collection):
col = collection.copy()
shuffle(col)
return col
def main(argv):
verbs = dict()
with open(os.path.join(HERE, 'verbs.csv')) as csvfile:
reader = csv.DictReader(csvfile, fieldnames=cols)
for i, row in enumerate(reader):
verbs[i] = row
loopctl = True
while verbs and loopctl:
idx = choice(list(verbs.keys()))
verb = verbs[idx]
print(f'\n{idx}>>> {verb["pl"]}?')
answers = []
for c in shuffled(cols[:3]):
print(f"{c}: ", end='')
answer = input()
if answer.strip() == 'q':
loopctl = False
break
if answer == verb[c]:
print("OK")
answers.append(True)
else:
print(f"wrong, correct is: {verb[c]}")
answers.append(False)
if all(answers) and len(answers) == 3:
print(f"{idx}: {', '.join(verb.values())} -> All OK")
verbs.pop(idx)
sleep(0.5)
if loopctl:
print('BRAVO!\n\nPress enter to finish...')
input()
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))