-
Notifications
You must be signed in to change notification settings - Fork 4
/
quiz2test.py
executable file
·55 lines (45 loc) · 1.3 KB
/
quiz2test.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
#!/usr/bin/python3
"""
Process (CSV) quiz files of the form:
Question, answer1, answer2....
Create includes for a test, and not a web form.
"""
import sys
import csv
QUESTION = 0 # type: int
FIRST_ANSWER = 1 # type: int
CORRECT = '^' # type: str
INDENT1 = " " # type: str
INDENT2 = INDENT1 + INDENT1 # type: str
INDENT3 = INDENT2 + INDENT1 # type: str
quiz_file = None # type: str
if len(sys.argv) < 2:
print("Must supply a quiz file.")
exit(1)
quiz_file = sys.argv[1]
answers = 'abcdefghijklmnopqrstuvwxyz' # type: str
if len(sys.argv) > 2:
delimiter = sys.argv[2] # type: str
else:
delimiter = ","
with open(quiz_file, "r") as f_in:
freader = csv.reader(f_in, delimiter=delimiter)
i = 1 # type: int
for row in freader:
print(INDENT1 + '<li>')
print(INDENT2 + row[QUESTION])
print(INDENT2 + '<ol type="a">')
j = 0 # type: int
for a in row[FIRST_ANSWER:]:
correct = "" # type: str
a = a.strip()
if a.startswith(CORRECT):
a = a[1:]
correct = " *"
print(INDENT3 + '<li>')
print(INDENT3 + a + correct)
print(INDENT3 + '</li>')
j += 1
print(INDENT2 + '</ol>')
print(INDENT1 + '</li>')
i += 1