-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpick-question.py
More file actions
65 lines (56 loc) · 1.88 KB
/
pick-question.py
File metadata and controls
65 lines (56 loc) · 1.88 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
60
61
62
63
64
65
from sys import argv, exit
import glob
import random
from PIL import Image
alldirs = ["R/",
"python/",
"clinical_data_science/",
"sql/",
"natural_language_processing/",
"machine_learning/",
"aws/",
"web_development/",
"others"]
if len(argv) == 1:
subdirs = alldirs
else:
subdirs = argv[1:]
for i, sd in enumerate(subdirs):
if not sd.endswith("/"):
subdirs[i] = sd + "/"
if not all(ele in alldirs for ele in subdirs):
print(f"Please choose from {alldirs}.")
exit()
random.seed() # use current system time as seed
# no repeating quesions
answered_questions = []
finished_subdir = []
while True:
subdirs = [sd for sd in subdirs if sd not in finished_subdir]
if len(subdirs) == 0:
print(f"You have answered all questions in {finished_subdir}")
break
# number of questions in each subdir and the chance of picking a subdir
# should be proportional to the number of questions
n_question_in_subdir = [len(glob.glob(sd + 'Q*')) for sd in subdirs]
subdir = random.choices(subdirs, n_question_in_subdir)[0]
questions = glob.glob(subdir + "Q*")
questions = [q for q in questions if q not in answered_questions]
if len(questions) == 0:
print(f"No more questions in {subdir}")
finished_subdir.append(subdir)
continue
question = random.choice(questions)
print(f"\n--- {question} ---")
answered_questions.append(question)
Image.open(question).show()
c = input("Press a for answer, q for quit, or Enter for next question > ")
if c == "a":
answer = question.replace("Q", "A")
print(f"\n--- {answer} ---")
Image.open(answer).show()
c = input("Press q for quit or Enter for next question > ")
if c == "q":
break
elif c == "q":
break