-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsections_questions.py
59 lines (47 loc) · 1.48 KB
/
sections_questions.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
class Section():
def __init__(self, chapter, number, questions=[]):
self.number = number
self.questions = questions
self.reading = None
self.chapter = chapter
def number(self):
return self.number
def questions(self):
return self.questions
def add_questions(self, questions):
for question in questions:
self.questions.append(question)
class Question():
def __init__(self, parent_section, number):
self.parent_section = parent_section
self.number = number
self.text = None
self.solution = None
def display(self):
return self.text
def display_solution(self):
return self.solution
def text_to_sections(text):
sections = []
for a in text:
a = a.split(" ")
if a[0].lower() == 'section':
chapter = int(a[1].split(".")[0])
num = int(a[1].split(".")[1].replace(':', ''))
questions = text_to_questions(a[2:], num)
sections += [Section(chapter, num, questions)]
return sections
def text_to_questions(ques_num, parent_section):
questions = []
for num in ques_num:
num = num.strip("\n")
num = num.strip(",")
num = num.strip(" ")
num = num.strip(",")
num = num.strip(".")
num = int(num)
questions+=[Question(parent_section, num)]
return questions
def parse_string(_file):
f = open(_file, 'r')
return f.readlines()