-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion_generator.py
More file actions
52 lines (43 loc) · 1.22 KB
/
question_generator.py
File metadata and controls
52 lines (43 loc) · 1.22 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
import os
while True:
try:
import docx
break
except:
os.system("pip install docx")
def newDoc(filename):
doc = docx.Document()
doc.save(filename)
return doc
def loadDoc(filename):
return docx.Document(filename)
def newQuestion(file, fileName):
question = input("Enter question: ")
num = stats(file)
paragraph = file.add_paragraph(str(num+1) + ". " + question + '\n')
for i in range(4):
answer = input("Enter answers: ");
paragraph.add_run('\t' + str(i+1) + '. ' + answer + '\n');
file.save(fileName)
def stats(file):
return len(file.paragraphs)
def main():
fileName = input("Enter filename: ")
badChars = ['<','>','?','\'','/','\\','*','|',':']
for c in badChars:
fileName = fileName.replace(c,'')
if not fileName.endswith(".docx"):
fileName += ".docx"
file = loadDoc(fileName) if os.path.exists(fileName) else newDoc(fileName)
#print(stats(file))
while True:
try:
print(stats(file)+1)
newQuestion(file, fileName)
os.system("cls")
except KeyboardInterrupt:
break
if __name__ == "__main__":
main()
else:
exit()