-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathquiz_combiner2.py
48 lines (37 loc) · 947 Bytes
/
quiz_combiner2.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
"""
Second version of quiz combiner: just shuffles questions.
"""
import sys
import random
NEW_Q_DELIM = "NewQuestion"
def usage():
"""
Prints usage message
"""
print("Usage: " + sys.argv[0] + " [filepath...]")
def read_questions(file_nm, questions):
question = ""
with open(file_nm, "r") as f:
for ln in f:
# print(f"{ln=}")
if ln.startswith(NEW_Q_DELIM):
if question:
questions.append(question)
question = ""
question += ln
questions.append(question)
return questions
def main():
# Read in the questions from files
quiz_files = sys.argv[1:]
if(len(quiz_files) == 0):
usage()
exit(1)
questions = []
for f in quiz_files:
read_questions(f, questions)
random.shuffle(questions)
for q in questions:
print(f"{q}")
if __name__ == "__main__":
main()