From 9b38af2d58e61bca6e563a2f011ae18b795a11fc Mon Sep 17 00:00:00 2001 From: Paul Wolneykien Date: Fri, 22 Apr 2022 01:06:04 +0300 Subject: [PATCH] Shuffle answers by default but add -n option to let not to shuffle them Signed-off-by: Paul Wolneykien --- quizgen.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/quizgen.py b/quizgen.py index 55e625f..2b5fdb0 100755 --- a/quizgen.py +++ b/quizgen.py @@ -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): @@ -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"]) @@ -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()