Skip to content

Commit

Permalink
Shuffle answers by default but add -n option to let not to shuffle them
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Wolneykien <[email protected]>
  • Loading branch information
wolneykien committed Apr 21, 2022
1 parent 7031989 commit 9b38af2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions quizgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def __init__(self, filename):
else:
self.filename = '%s.quiz' % filename

self.randomize = False;
self.randomize_questions = False;
self.randomize_answers = True;


def get_filename(self):
Expand Down Expand Up @@ -209,9 +210,12 @@ def parse(self):
except:
raise Exception('ERROR. Are you sure you started every problem group with "[]"?')

if self.randomize:
if self.randomize_questions:
for pg in quiz["problem_groups"]:
random.shuffle(pg["questions"])

if self.randomize_answers:
for pg in quiz["problem_groups"]:
for ql in pg["questions"]:
random.shuffle(ql["options"])

Expand Down Expand Up @@ -606,13 +610,18 @@ def main():
elif '-c' in sys.argv[1]:
create_sample()
else:
randomize = False
randomize_questions = False
randomize_answers = True
if '-r' in sys.argv[1]:
sys.argv.pop(1)
randomize = True
randomize_questions = True
if '-n' in sys.argv[1]:
sys.argv.pop(1)
randomize_answers = False
for filename in sys.argv[1:]:
quiz_parser = QuizParser(filename)
quiz_parser.randomize = randomize
quiz_parser.randomize_questions = randomize_questions
quiz_parser.randomize_answers = randomize_answers

quiz = quiz_parser.parse()

Expand Down

0 comments on commit 9b38af2

Please sign in to comment.