/
setup.py
69 lines (54 loc) · 1.85 KB
/
setup.py
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
66
67
68
import docx
import random
import easygui
def getText(filename):
doc = docx.Document(filename)
fullText = []
for para in doc.paragraphs:
fullText.append(para.text)
return '\n'.join(fullText)
def getQuestions(filename):
text = getText(filename)
questions = {}
for question in text.split("MSC"):
try:
questions[question.split("ANS: ")[0]] = question.split('ANS: ')[1]
except IndexError as e:
pass
return questions
def setupSession(chapters):
qnum = easygui.integerbox("How many questions should be asked?")
if not (easygui.ynbox("Asking from all chapters, YES to continue or NO to select chapters.")):
cstart = easygui.integerbox("Chapter to start: ")
clen = easygui.integerbox("How many chapters should be included (Max 22): ")
else:
cstart = 0
clen = 22
return qnum, chapters[cstart:cstart + clen]
def endSession():
return not easygui.ccbox("Do you want to continue?")
def askQuestions(n=5, chapter_list=[]):
testbank = dict()
for chapter in chapter_list:
testbank.update(chapter)
question_list = list(testbank.keys())
for _ in range(n):
key = random.choice(question_list)
if testbank[key][0] in ["T", "F"]:
choice = showQuestion(key, 0)
else:
choice = showQuestion(key, 1)
# i = input(key + ': ').upper()
checkAnswer(choice, testbank[key])
def showQuestion(question, qtype):
# qtype 0: true/false, qtype 1: multiple choice
if qtype == 0:
answer = ("T", "F")
if qtype == 1:
answer = ("A", "B", "C", "D")
return easygui.buttonbox(question, 'Answer: ', answer)
def checkAnswer(choice, truth):
if choice == truth[0]:
easygui.msgbox('Correct!')
else:
easygui.msgbox('Incorrect, should have been ' + truth)